从.txt文件在线读取列表中的列表box vb.net



我正在尝试从在线链接中读取列表框,例如:http://blahblah.com/list.txt到listbox中。每行进入新的列表框项目。

我可以通过做

来解决这个问题
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

最新更新