在此脚本中,我试图读取Web服务器上txt文件的行并将其显示在列表框中,但未读取新行!
public byte[] GetFileViaHttp(string url)
{
using (WebClient client = new WebClient())
{
return client.DownloadData(url);
}
}
private void Form1_Load(object sender, EventArgs e)
{
var result = GetFileViaHttp(@"https://www.lunabooster.com/list/script-list.txt");
string str = Encoding.UTF8.GetString(result);
string[] strArr = str.Split(new[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries);
for (int i = 0; i < strArr.Length; i++)
{
OpenSourceListBox.Items.Add(strArr[i].ToString());
}
}
答案 0 :(得分:2)
如果将\r\n
更改为\n
,我将测试您的代码并可以正常工作。
更改此内容:
string[] strArr = str.Split(new[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries);
收件人:
//
string[] strArr = str.Split(new[] { "\n" }, StringSplitOptions.RemoveEmptyEntries);