2013-07-02 27 views
0

首先之後,我仍然在VB.net新我曾遇到一個奇怪的問題VB.net自動換行復制

我創造了一個工具,將拆分內容從多線文本框阿成的線字符串並添加一些字符並將其加入並顯示在另一個多行文本框B中(A - >拆分內容 - >添加字符 - >加入 - >顯示在B中)。樣本會是這樣

原始數據從A:

This 
is 
a 
test 
data 

結果中顯示。B:

Row 0 = This 
Row 1 = 
is 
Row 2 = 
a 
Row 3 = 
test 
Row 4 = 
data 

的源代碼是:

Row 0 = This 
Row 1 = is 
Row 2 = a 
Row 3 = test 
Row 4 = data 

結果從乙COPIED

tempA = "" 
tempB = "" 

tempA = A.Text() 
stringAry = tempA.Split(Environment.NewLine) 
For iCounter As Integer = 0 To stringAry.Length - 1 
tempB = tempB + "Row " + iCounter.ToString + " = " + stringAry(iCounter).ToString +  Environment.NewLine 
Next 
B.Text() = tempB 

所以我可以知道爲什麼複製的結果與顯示的結果不同,我怎麼解決這個問題?

+0

問題在哪裏?我可以看到示例代碼和源代碼,但是你在問什麼? –

+0

對不起,我想問的是爲什麼複製的結果會與顯示的結果不同,我該如何解決這個問題 – Robert

+0

在你的源代碼中,只有你從A獲取原始數據並顯示結果B.你的意思是由B的COPIED結果?如果我手動將內容從B複製到記事本,則獲得相同的結果/格式。 – tezzo

回答

0

您應該從stringAry(iCounter)值中刪除任何不需要的新行字符。

tempA = "" 
tempB = "" 

tempA = A.Text() 
stringAry = tempA.Split(Environment.NewLine) 
For iCounter As Integer = 0 To stringAry.Length - 1 
tempB = tempB + "Row " + iCounter.ToString + " = " + stringAry(iCounter).ToString.Replace(Environment.NewLine, string.Empty) +  Environment.NewLine 
Next 
B.Text() = tempB 
+0

我曾試圖加入如下 TEMPA = 「」 tempB = 「」 TEMPA = A.Text() stringAry = tempA.Split(環境之前更換來自每個陣列的任何Environment.NewLine和vbCrLf。 NewLine) iCounter As Integer = 0 To stringAry.Length - 1 sTemp = stringAry(iCounter).Replace(Environment.NewLine,「」) tempB = tempB +「Row」+ iCounter.ToString +「=」+ sTemp + Environment.NewLine Next B.Text()= tempB 但似乎似乎輸出仍然是相同的 – Robert