views:

152

answers:

3

I'm trying to replace "\v" in the string "Lapensee\v" with ""

string a = "Lapensee\v";
string b = a.Replace("\\v", "");
Console.WriteLine(b);

Output: Lapensee\v

Can anyone explain why this doesn't work?

+1  A: 

\v in your string 'a', needs to be escaped too. Else it will be interpreted as a vertical tab.

leppie
+1  A: 

I think you meant either:

string a = "Lapensee\\v";

or

string b = a.Replace("\v", "");
280Z28
The data was imported from SQL and the string actually shows as Lapensee\v in the debugger. The vertical quote is causing another code block to fail and I need to remove it when the data is brought into the application.
In that case, it's the latter line of code you are interested in. :)
280Z28
+2  A: 
string a = "Lapensee\v";
string b = a.Replace("\v", ""); // You don't want the double \\ 
Console.WriteLine(b);

Since you have \v in the string a, you should also replace it with \v.

Per Hornshøj-Schierbeck
That works. Thanks.