假设我采集了一个页面的N条链接,现在我想把这N条链接一条一条传到文本框(多行)中该如何去做呢?谢谢各位指教下小弟

解决方案 »

  1.   

    foreach (string link in links)
    {
      TextBox1.Text += link + "\r\n";
    }
      

  2.   

    使用了foreach (string link in links)
    {
      TextBox1.Text += link + "\r\n";
    }
    为何会提示无法将char类型转换为string类型呢?这个该如何解决
      

  3.   

    先用 .ToString 转换下 可能你的编码有问题
      

  4.   

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Net;
    using System.Text.RegularExpressions;
    using System.Windows.Forms;namespace FormMain
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }        private void btnDefine_Click(object sender, EventArgs e)
            {
                int one=Convert.ToInt32(textBox1.Text);
                int tow=Convert.ToInt32(textBox2.Text);
                WebClient webrespen = new WebClient();
                webrespen.Credentials = CredentialCache.DefaultCredentials;//获取或设置用于对向Internet资源的请求进行身份验证的网络凭据。
                byte[] pagedata = null;//用于获取指定的链接
                string pageHtml = string.Empty;//接受解码后的数据 
                string strregex = "\\bhttp://www\\.amazon.cn/mn/detailApp/ref=sr_1_\\d+\\?_encoding=UTF8&s=books&qid=\\d+&asin=\\w+&sr=1-\\d+\\b";
                string regex=string.Empty;
                
                for (int i = one; i <=tow; i++)
                {
                    string strurl = "http://www.amazon.cn/s/ref=?ie=UTF8&n=658490051&page=" + i.ToString();
                    pagedata = webrespen.DownloadData(strurl);//从指定网站下载数据
                    pageHtml = Encoding.UTF8.GetString(pagedata);//如果获取网站页面采用的是UTF-8,则使用这句
                    regex=Regex.Match(pageHtml,strregex).ToString();
                    foreach (string  item in regex )
                    {
                        textBox3.Text = item + "\r\n";
                    }
                }
                
            }
        }
    }
      

  5.   


            //regex=Regex.Match(pageHtml,strregex).ToString();
            foreach (var item in Regex.Matches(pageHtml,strregex))
            {
                 textBox3.Text = item.ToString() + "\r\n";
            }
      

  6.   

    textBox3.Text = item + "\r\n";
    修改为:textBox3.Text += item + "\r\n";
     
      

  7.   

    明白了……
    呵呵
    MARK!