C# how to replace Slash Quote \\\"

时光毁灭记忆、已成空白 提交于 2019-11-29 16:40:27

If you put an @ before the string, the string becames "literal" without using control characters or escapes (with the backslahses).

So @"hello\nico" will result in a string with the words "hello" and "nico" separated by a slash and not the words "hello" and "ico" separated by a line feed.

You can also define a string without the @ and with control characters like this: "hello\\nico" which will have the same result. The first backslash is a control character, not an actual value inside the string.

Be aware: if your IDE / debugger shows a value of a string, at will also use the second format to display the text. So the backslash inside the string will be escaped by putting another backslash before it. It looks like the string contains double slashes, but it does not. You can verify this by:

  • Checking the length of the string and count the characters.
  • Write the value to an output like Debug.WriteLine or Console.WriteLine which will show that string as it is, without the slashes as escapes.

You say: Every time I do it, it becomes a search for src=\\"/ instead of src=\"/. Are you sure? I think you are fooled by the IDE / debugger which will show the string with an second backslash, which is just a control character.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!