Corrected: string.Replace acts unexpectedly in this case

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Grrrr... I couldn't edit my previous post. Lemme short circuit the obvious
reply by fixing my code.

string foo = @"v:\\bar.txt";
foo.Replace(@"\\",@"\");
if(foo == @"v:\\bar.txt)
MessageBox.Show("Why didn't Replace replace?");
 
foo.Replace(@"\\",@"\");

Replace doesn't modify the existing string (because strings are
immutable), it returns a new string. Change that line to

foo = foo.Replace(@"\\",@"\");



Mattias
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top