简体   繁体   中英

Not reading new lines from txt file on webserver

In this script, I'm trying to read lines of a txt file on my web server and display it to a list box but it is not reading new lines!

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());
    }
}

I test your code and work fine if you change \\r\\n to \\n .

Change this :

string[] strArr = str.Split(new[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries);

To:

//                                      
string[] strArr = str.Split(new[] { "\n" }, StringSplitOptions.RemoveEmptyEntries);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM