替换“\”字符的问题

Problems with replacing "\" character

也许有人可以帮我解决以下问题。我有包含“\line”的文本,例如 Username \line Firstname \line。我想用 \r\n 替换它。我的代码:

string _text = query;
_text.Replace("\Line", " \r\n");

它给出以下错误:无法识别的转义序列。

有人知道解决方案吗?

谢谢!

您需要转义反斜杠

_text.Replace("\Line", " \r\n");

或者你可以试试字符串文字(虽然没试过):

_text.Replace(@"\Line", " \r\n");