如何从字符串c#中删除\ r \ n
我试图找出一个简单的方法从字符串中删除\ r \ n。
示例:text =“this.is.a.string。\ r \ n \ nthis.is.a.string \ r \ n”
我试过了:
text.Replace("\r\n", "")
和text.Replace("\r\n", string.Empty)
但它不起作用。 \r\n
仍然在字符串中……
结果应为:“this.is.a.string.this.is.a.string”
读得更好:
text = text.Replace(System.Environment.NewLine, string.Empty);
它返回一个值。 你需要说text = ...
text = text.Replace(@"\r\n", "");
您是否将返回值设置回变量?
text = text.Replace(@"\r\n", "");
试试这个
text = text.Replace(System.Environment.NewLine, "");
你最好试试这个。
text = text.Replace("\r\n", "");
希望这项工作。
试试这个。
text = text .Replace("\\r\\n", "");
这对我有用;)
有时您无法从json字符串替换新行。 以下代码将消除所有机会。
json = json.Replace(Environment.NewLine, "").Replace("\r\n", "").Replace("\r", "").Replace("\n", "").Replace("\\r", "").Replace("\\n", "");