[英]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.