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
 
Back
Top