我有一个以下格式的字符串
string s = "This is a Test String.\n This is a next line.\t This is a tab.\n'
我想删除上面字符串中所有出现的\n
和\r
.
我试了string s = s.Trim(new char[] {'\n', '\r'});
次,但没用.
我有一个以下格式的字符串
string s = "This is a Test String.\n This is a next line.\t This is a tab.\n'
我想删除上面字符串中所有出现的\n
和\r
.
我试了string s = s.Trim(new char[] {'\n', '\r'});
次,但没用.
我喜欢使用正则表达式.在这种情况下,您可以:
string replacement = Regex.Replace(s, @"\t|\n|\r", "");
正则表达式在世界上并不流行.NET世界,但它们提供了很多处理字符串的能力.