如何从字符串中删除回车返回
问题描述:
我想处理一个字符串,以便它不包含回车符,但是我遇到了一些麻烦。我目前正在使用:如何从字符串中删除回车返回
Visual Studio 2010中:
strText = strText.Replace(vbCr, "")
回车没有被删除,谢谢。
答
你试过
strText = strText.Replace("\n\r", "");
或
strText = strText.Replace("\n", "");
或
strText = strText.Replace("\r", "");
或
strText = strText.TrimEnd('\r', '\n');
的另一个选项使用'Environment.NewLine'而不是硬编码的字符串。 – 2013-04-26 15:41:51
的确如此,那会更好。 – 2013-04-26 15:42:28
虽然在Visual Basic中'vbCrLf'可能是正确的常量。从而提示这个问题。 – 2013-04-26 15:45:44