开发者

Remove escape sequence in c#

I would like to replace the escape sequence from string test= "\"hi hello\" " to string test=" "hi hello" ". Basically I want to 开发者_Go百科replace \" to ". Any suggestions?


This is not possible, as if you remove the escape sequences, you will have an invalid string.

You can use verbatim string literals, but these also require escaping of double quotes.

Can you please explain why you want to remove the escape sequences? They will not be visible when you output a string.

The debugger will display the escape sequences as an aid, but if you output the string, you will not see them.

Console.Out.WriteLine("\"hi there \"");
// outputs "hi there "


string test = "\"hi hello\" ";
test.Replace("\"", "");
Console.Out.WriteLine(test);

This produces

hi hello

on the Console.


test = test.Replace("\\", "");

If you're not looking for replacing \ in a string, your options are limited to a verbatim string:

string test = @" ""hi hello"" ";

Note the \" was replaced with ""

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜