2013-11-04 115 views
0

我有下面的代碼;VB.NET不需要的額外中斷

Dim orderlist As List(Of String) = New List(Of String) 
For i As Integer = 0 To newacctlist.Items.Count - 1 
    orderlist.Add("This order will be placed on" & newacctlist.Items(i)) 
Next (i) 
Textbox1.Lines = orderlist.ToArray 

當我導入項目從txt文件,作爲結果,第一個我出來是正確的,但未來的人得到一個不需要休息。他們出來的:從txt文件

This order will be placed on 
Monday 

,而不是

This order will be placed on Monday 

進口

Dim a As String = My.Computer.FileSystem.ReadAllText(path & "\neworder.txt") 
Dim b As String() = a.Split(vbNewLine) 
newacctlist.Items.AddRange(b) 

如何解決這個問題?

在此先感謝

回答

3

修剪它,

orderlist.Add("This order will be placed on" & newacctlist.Items(i).Trim ) 
---------------------------------------------------------------------^ 
+0

它的工作!我很感激幫助 –

1

我能想到的唯一的事情是,你必須在你的newacctlist -items一個newline字符數限制。

orederlist.Add()行放置一個斷點並檢查這些值。

另請參閱創建newacctlist的代碼。 可能你的罪魁禍首就在那裏。

**編輯**

您對vbNewLine分裂包括它的字符串中。

Dim a As String = My.Computer.FileSystem.ReadAllText(path & "\neworder.txt") 
Dim b As String() = a.Split(vbNewLine) 
For Each s As String In b 
    Console.WriteLine(s.Replace(vbCr, "").Replace(vbLf, "")) 
Next 
+0

謝謝,修剪做的工作,但我會嘗試這個問題,以及 –