簡體   English   中英

將.txt文件在線列表讀入列表框VB.NET

[英]Read list from .txt file online into listbox VB.NET

我試圖從在線鏈接中讀取列表框,例如: http//blahblah.com/list.txt到列表框中。 每行進入一個新的列表框項目。

我可以做到這一點

dim wc as new webclient
textbox.text = wc.downloadstring("http://blahblah.com/list.txt")

然后將其保存為.txt文件,然后將其讀入行列表框行。

我想跳過這一步,直接從在線文本文件中讀取..

謝謝,我將回答您幫助我使用此代碼所需的任何問題。 謝謝一堆。

如果不先下載,您無法直接從文件中讀取各行。 它僅作為文本文件提供; 您必須先檢索該文件的內容,然后才能訪問它們。

但是,您可以在不將其保存到實際文本文件中的情況下執行此操作。 將文件內容讀入String變量,使用String.Split創建包含各行的數組,然后將該數組中的項添加到ListBox

Dim Lines() As String
Dim stringSeparators() As String = {vbCrLf}
Dim Source As String
Dim wc as new WebClient

Source = wc.downloadstring("http://blahblah.com/list.txt");
Lines = Source.Split(stringSeparators, StringSplitOptions.None)
ForEach s As String in Lines
    ListBox1.Items.Add(s)
Next

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM