C# 删除换行符不起作用

C# 删除换行符不起作用,c#,C#,所以我有这个方法: public static string ToProperText(this HtmlHelper helper, string text) { System.Diagnostics.Debug.WriteLine(text); System.Diagnostics.Debug.WriteLine(text.Replace("\r\n", "")); string lineSeparator = ((char)0x2028).ToString();

所以我有这个方法:

public static string ToProperText(this HtmlHelper helper, string text)
{
    System.Diagnostics.Debug.WriteLine(text);
    System.Diagnostics.Debug.WriteLine(text.Replace("\r\n", ""));

    string lineSeparator = ((char)0x2028).ToString();
    string paragraphSeparator = ((char)0x2029).ToString();

    System.Diagnostics.Debug.WriteLine(text.Replace("\r\n", string.Empty).Replace("\n", string.Empty).Replace("\r", string.Empty).Replace(lineSeparator, string.Empty).Replace(paragraphSeparator, string.Empty));
    System.Diagnostics.Debug.WriteLine(text.Replace("a", ""));
    return null;
}
使用数据库中的某些数据调用时,这是输出:

<p>\r\n Vanaf nu worden de websiteberichten ook <u>automatisch</u> in de Nieuwssectie op het <strong>forum</strong> geplaatst.</p>\r\n
<p>\r\n Vanaf nu worden de websiteberichten ook <u>automatisch</u> in de Nieuwssectie op het <strong>forum</strong> geplaatst.</p>\r\n
<p>\r\n Vanaf nu worden de websiteberichten ook <u>automatisch</u> in de Nieuwssectie op het <strong>forum</strong> geplaatst.</p>\r\n
<p>\r\n Vnf nu worden de websiteberichten ook <u>utomtisch</u> in de Nieuwssectie op het <strong>forum</strong> gepltst.</p>\r\n
无论我做什么,都不会从字符串中删除\r\n,尽管其他替换项也可以。知道这是怎么回事吗

谢谢

试试看

System.Diagnostics.Debug.WriteLine(text.Replace(@"\r\n", ""));
查找添加的@符号。

试试看

System.Diagnostics.Debug.WriteLine(text.Replace(@"\r\n", ""));

查找添加的@符号。

在此处猜测。。您是否尝试过:

text.Replace("\\r\\n", "")?
\r\n将替换实际的换行符,而不是实际的文本“\r\n”:


或者,duluca的选择也应该有效。

在这里猜测。。您是否尝试过:

text.Replace("\\r\\n", "")?
\r\n将替换实际的换行符,而不是实际的文本“\r\n”:


或者,duluca的选项也应该起作用。

字符串可能已经转义了。试一试

text.Replace("\\r\\n")

字符串可能已经转义了。试一试

text.Replace("\\r\\n")

您是否尝试过将回车和换行分开而不是一起拆下?哦,没关系,我猜你是想删除实际的角色。一开始你没有注意到。你有没有试过把回车和换行分开,而不是一起拆?哦,没关系,我猜你是想删除实际的角色。一开始我没注意到。