By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,853 Members | 938 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,853 IT Pros & Developers. It's quick & easy.

Corrected: string.Replace acts unexpectedly in this case

P: n/a
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?");
Nov 22 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
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

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Nov 22 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.