2013-04-26 84 views
0

我想處理一個字符串,以便它不包含回車符,但是我遇到了一些麻煩。我目前正在使用:如何從字符串中刪除回車返回

Visual Studio 2010中:

strText = strText.Replace(vbCr, "") 

回車沒有被刪除,謝謝。

回答

0

你試過

strText = strText.Replace("\n\r", ""); 

strText = strText.Replace("\n", ""); 

strText = strText.Replace("\r", ""); 

strText = strText.TrimEnd('\r', '\n'); 
+1

的另一個選項使用'Environment.NewLine'而不是硬編碼的字符串。 – 2013-04-26 15:41:51

+0

的確如此,那會更好。 – 2013-04-26 15:42:28

+0

雖然在Visual Basic中'vbCrLf'可能是正確的常量。從而提示這個問題。 – 2013-04-26 15:45:44