string replace() problem
-
string aa = "\document\test"; aa = aa.Replace("\", "\\"); --- this line C# doesn't like it?? I want to replace '\' in string aa to "\\". How to do it?
You have to escape your chars :rolleyes: Alex Korchemniy
-
string aa = "\document\test"; aa = aa.Replace("\", "\\"); --- this line C# doesn't like it?? I want to replace '\' in string aa to "\\". How to do it?
I suspect the problem is that \d and \t are valid escape values, so you've not realised the problem. To put a \ in your string, either put two or, ( my preferred option ), use @. With @ at the start, everything is literal, the only escape is double quotes to do quotes. string aa = "\document\test"; The value here is ocument test, where the spaces are a tab string aa = @"\document\test"; string aa = "\\document\\test"; These both set the string as you'd expect Christian Graus - Microsoft MVP - C++
-
string aa = "\document\test"; aa = aa.Replace("\", "\\"); --- this line C# doesn't like it?? I want to replace '\' in string aa to "\\". How to do it?
-
string aa = "\document\test"; aa = aa.Replace("\", "\\"); --- this line C# doesn't like it?? I want to replace '\' in string aa to "\\". How to do it?
string aa = @"\document\test"; aa = aa.Replace(@"\", @"\\") ; Sanjay Sansanwal www.sansanwal.com
-
string aa = "\document\test"; aa = aa.Replace("\", "\\"); --- this line C# doesn't like it?? I want to replace '\' in string aa to "\\". How to do it?