2015-05-24 33 views
1

我有一個位於我的服務器上的文本文件。stringbuilder中的拆分字符串

的文本文件的內容是這樣的一個

hello,200 
james,300 
robin,100 

而這就是我的編碼到現在爲止,並在StringBuilder的迭代爲每個測試項目,但它並沒有遍歷每個項目。我不明白問題在哪裏。

任何幫助非常讚賞

WinHttp.Open("GET", "http://mytmmt.cafe24.com/test.txt") 
WinHttp.Send() 
Dim sb As New System.Text.StringBuilder 
sb.Append(WinHttp.ResponseText) 
Dim lines() As String = Split(sb.ToString, vbNewLine) 
For Each line As String In lines 
    Debug.Print(line) '<---------here should have to print but this line skip 
Next 

回答

0

使用StringRerader會讓你的文本的閱讀更容易控制,這將解決您的問題:

WinHttp.Open("GET", "http://mytmmt.cafe24.com/test.txt") 
WinHttp.Send() 
Using sr As IO.StringReader = New IO.StringReader(WinHttp.ResponseText) 
    Do 
     line = sr.ReadLine 
     'Do something with "line" 
    Loop Until String.IsNullOrEmpty(line) 
End Using 
+0

它工作!謝謝! –

0

如果我看到該鏈接「http://mytmmt.cafe24.com/test.txt」的結果,它與白的空間,但不能與新的換行。與下面的空間拆分。

WinHttp.Open("GET", "http://mytmmt.cafe24.com/test.txt") 
WinHttp.Send() 
Dim sb As New System.Text.StringBuilder 
sb.Append(WinHttp.ResponseText) 
Dim lines() As String = Split(sb.ToString, " ") 
For Each line As String In lines 
    Debug.Print(line) '<---------here should have to print but this line skip 
Next 
+0

感謝您的回覆!我測試過,但它也跳過debug.print(行)。我真的不明白哪裏是問題。 –

+0

替換爲「Chr(10)」(換行)如下。 Dim sep As Char = Chr(10) Dim lines()As String = result.ToString.Split(sep) Console.WriteLine(lines.Length) For Each行As String In行 Console.WriteLine(line) 下一個 –

+0

謝謝!也在工作 –