我正在尝试找出一种简单的方法从字符串中删除\r\n。
例子: text = "this.is.a.string.\r\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);
.NET中的字符串是不可变的,因此您无法更改现有字符串 - 您只能创建新字符串。 Replace
方法返回修改后的结果,即。
text = text.Replace(System.Environment.NewLine, string.Empty);
text = JObject.Parse(text);
text = text.Replace(@"\r\n", "");
text = ...
语句。text = text.Replace(@"\r\n", "");
试试这个:
text = text.Replace(System.Environment.NewLine, "");
请试一试。
text = text .Replace("\\r\\n", "");
这对我有用;)
你最好试一下这个。
text = text.Replace("\r\n", "");
string.replace()
。 - Rahultext.Replace()
的结果赋值给某个地方吗?它不会就地替换。 - zerkms