我有一个字符串
var string = "I have a a string \\nThis is a new line\\nThis is another";
what I want is
var string = "I have a a string \nThis is a new line\nThis is another";
我使用过
string.Replace("\\","\");
Newline in constant
但是出现了“常量中的换行符”错误信息。
\\r
(文字\
+r
)转换为\r
(CR 符号),juharr 将不得不使用链接的Replace
方法。很多事情取决于输入字符串本身、它的来源以及可能包含的内容。 - Wiktor StribiżewRegex.Unescape()
,特别是对于初学者。 - Alan MooreRegex.Unescape
超过5年,它非常有效。只要正确记录并明智使用即可。 - Wiktor Stribiżew\\t
和\\n
这样的序列,这些序列可以转换为实际字符。例如,\\s
会抛出异常。我还尝试了\\b
,半期望它删除前一个字符,但它只是变成了空白。 - Alan Moore