0

我有这个回显到一个空白页:

echo "Testing|Testing1|Testing2|Testing3|Testing4<br/>";
echo "Something|Something1|Something2|Something3|Something4";

现在我有一个列表视图。在此示例中,它将创建 2 行 5 列。所以我的问题是,如何逐行阅读以正确创建网站上显示的行数?

到目前为止,这是我的代码:

WebClient client = new WebClient();
string downloadString = client.DownloadString("https://example.com/Testing.php");

string[] downloadString2 = downloadString.Split(
    new char[] 
    { 
        (char)'|' 
    }, System.StringSplitOptions.RemoveEmptyEntries);

ListViewItem item = new ListViewItem(
    new[] 
    { 
        downloadString2[0].ToString(), 
        downloadString2[1].ToString(), 
        downloadString2[2].ToString(), 
        downloadString2[3].ToString(), 
        downloadString2[4].ToString() 
    });
listView1.Items.Add(item);

(列已在列表视图中创建)

- 编辑:这对我来说很好:

        WebClient client = new WebClient();
        string downloadString = client.DownloadString("https://example.com/Testing.php");

        string[] stringSeparators = new string[] { "<br/>" };
        string[] Lines = downloadString.Split(stringSeparators, StringSplitOptions.None);

        string[] things = new string[5]; // Fixed size. I might find a way later to make it dynamically
        int i = 0;

        foreach (string line in Lines)
        {
            string[] words = line.Split('|');
            i = 0;
            foreach (string word in words)
            {
                things[i] = word;
                i++;

            }

            ListViewItem item = new ListViewItem(
                new[] 
                { 
                    things[0], 
                    things[1], 
                    things[2], 
                    things[3], 
                    things[4] 
                });
            listView1.Items.Add(item);
        }
4

1 回答 1

3

不完全是你想要的,但你可以试试这个

   WebClient client = new WebClient();
   string downloadString = client.DownloadString("https://example.com/Testing.php");

   string[] stringSeparators = new string[] {"<br/>"};
   string[] Lines = downloadString.Split(stringSeparators, StringSplitOptions.None);
   foreach (string line in Lines)
   {
        string[] words = line.Split('|');
        foreach (string word in words)
        {

                 ListViewItem item = new ListViewItem();
                 item.add(word);

        }
       listView1.Items.Add(item);
    }
于 2013-03-12T02:25:53.723 回答