string[] strArray = http.Split(new char[] { ',' });
  bean.url = strArray[1];
 lst.Add(bean);
 this.SetDataGrid(lst);
 this._urlList = lst;读取的文件格式是
1,需要的字符串
2,需要的字符串标红代码部分跟踪获取到的数组是"1""需要的字符串/r/n2" "需要的字符串/r/n3"而lst.Add(bean)
中只获取到
"需要的字符串/r/n2"
这一条数据 帮帮忙吧

解决方案 »

  1.   

    string[] strArray = http.Split(','); 
    foreach (string bean in strArray)
    {
      lst.Add(bean); 
    }
      

  2.   

    string[] strArray = http.Split(new string[] { ",","/r/n" }); 
      

  3.   

    少了个参数
    string[] strArray = http.Split(new string[] { ",","/r/n" },StringSplitOptions.None); 
      

  4.   

    string[] strArray = http.Split(",","\r\n"); 
      

  5.   

    无法将类型“string”隐式转换为“char”
      

  6.   

    string[] strArray = System.Text.RegularExpressions.Regex.Split(http, @",|\r\n"); 
      

  7.   

    string[] strArray = System.Text.RegularExpressions.Regex.Split(http, @"/r/n\d,"); 
      

  8.   

    写个正则吧
    System.Text.RegularExpressions.Regex.Split(http, @"/r/n\d,"); 
    很好很强大
      

  9.   

    而lst.Add(bean) 
    中只获取到 
    "需要的字符串/r/n2" 
    这一条数据 
    5555各位大侠忽略了这个原本是while (xxx.Peek() >= 0)本地打开文件命令可以读取下一个字符而不使用他~~~~
    string  我找不到方法搞定先谢谢wuyi8808 至少能循环了,你的两次回帖相当牛逼~~~啊哦 可是 我的lst.Add(bean)只能读到第一条数据,后面的就读取不到了
      

  10.   

     ArrayList lst = new ArrayList();
                        urlBean bean = new urlBean();
                        string[] strArray = System.Text.RegularExpressions.Regex.Split(http,"\r\n");
                       
                        foreach (string i in strArray)
                            {
                                //this.dataGridView1["url", strArray.Length].Value = strArray.ToString();
                                bean.url = strArray[0].ToString();
                                //this.tishikuang.AppendText(strArray[0].ToString() + "\r\n");
                                lst.Add(bean);
                                this.SetDataGrid(lst);
                                this._urlList = lst;
                            }
                                this.tishikuang.AppendText("数据读取成功!\r\n");数据为
    1234567
    7654321
    0000000

    循环三次 读取出了第一条数据………………
      

  11.   

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;
    using Microsoft.VisualBasic;
    using System.IO;
    using System.Net;
    using System.Runtime.InteropServices;
    using mshtml;
    using System.Collections;
    using System.Collections.ObjectModel;
    using System.Diagnostics;
    using System.Media;
    using System.Runtime.CompilerServices;
    using System.Threading;
    namespace 读取网络文本文件
    {
              public partial class chuangkou1 : Form
            {
        
                private ArrayList _urlList;            
               public chuangkou1()
                {
                    InitializeComponent();
                }
                //开始读取网络文本信息
                private void duquxinxi_Click(object sender, EventArgs e)
                {
                    
                    string http = HttpUtil.GetHttp("http://127.0.0.1/test.txt", null);
                    
                    string duurlpd = "1";
                    if (http.IndexOf(duurlpd) == -1)
                    {
                        this.tishikuang.AppendText("对不起,文本文件配置错误!");
                        return;
                    }                                    ArrayList lst = new ArrayList();
                        urlBean bean = new urlBean();
                        string[] strArray = System.Text.RegularExpressions.Regex.Split(http,"\r\n");
                       
                        foreach (string i in strArray)
                            {
                                //this.dataGridView1["url", strArray.Length].Value = strArray.ToString();
                                bean.url = strArray[0].ToString();
                                //this.tishikuang.AppendText(strArray[0].ToString() + "\r\n");
                                lst.Add(bean);
                                this.SetDataGrid(lst);
                                this._urlList = lst;
                            }
                                this.tishikuang.AppendText("数据读取成功!\r\n");
                           
                   
                }         
              
                private void SetDataGrid(ArrayList lst)
                {
                    this._urlList = lst;
                    this.dataGridView1.Rows.Clear();
                    int num = -1;
                    int num3 = lst.Count - 1;
                    for (int i = 0; i <= num3; i++)
                    {
                        this.dataGridView1.Rows.Add();
                       urlBean bean = (urlBean)lst[i];
                        this.dataGridView1["index", i].Value = i + 1;
                        this.dataGridView1["url", i].Value = bean.url;
                                         
                    }
                }
                 //*/ 
            }
        public class AdUrlBean
        {
            public string newUrl = "";
            public string oldUrl = "";
        }
        public class urlBean
        {
           // public string id = "";
            public string url = "";
        }
        public class HttpUtil
        {
            public static string _checkCode = null;
            private static CookieCollection _cookieCheckCode = new CookieCollection();
            private static CookieCollection _cookieCollection = new CookieCollection();
            public static string _password = null;
            public static string _userId = null;        public static void Clear()
            {
                _cookieCheckCode = new CookieCollection();
                _cookieCollection = new CookieCollection();
                _userId = null;
                _password = null;
                _checkCode = null;
            }        public static string GetHttp(string url, [Optional, DefaultParameterValue(null)] Encoding eccode)
            {
                string str;
                Stream responseStream = null;
                HttpWebRequest request = null;
                StreamReader reader = null;
                if (eccode == null)
                {
                    eccode = Encoding.UTF8;
                }
                CookieContainer container = new CookieContainer();
                try
                {
                    container.Add(_cookieCollection);
                    request = (HttpWebRequest)WebRequest.Create(url);
                    request.CookieContainer = container;
                    request.Method = "GET";
                    request.Accept = "*/*";
                    request.Timeout = 0x4e20;
                    request.UserAgent = "Mozilla/4.0";
                    responseStream = ((HttpWebResponse)request.GetResponse()).GetResponseStream();
                    if (responseStream != null)
                    {
                        reader = new StreamReader(responseStream, eccode);
                        return reader.ReadToEnd();
                    }
                    str = "";
                }
                catch (Exception exception1)
                {
                    //ProjectData.SetProjectError(exception1);
                    Console.WriteLine(url + ":" + exception1.ToString());
                    str = "";
                   // ProjectData.ClearProjectError();
                }
                return str;
            }
        }
        }
      

  12.   

    string[] strArray = http.Split(new string[] { "\r\n","," }); 
      

  13.   

    1234567
    7654321
    0000000这既是我的实际文本原本想用,分割,但看了一些人的回复 发现可以直接用回车分割所以改了一点但是这样dataGridView1的url 只能循环输出第一条也就是 1234567
      

  14.   


    bean.url = strArray[0].ToString(); 把0改成i
      

  15.   

    谢谢楼上的兄弟回复郁闷ing改成i出错
      

  16.   


    看错了..
    这里应该是:                  
                        foreach (string s in strArray) //把i改成s把,看着顺眼一些.
                            {                             bean.url = s;
                                lst.Add(bean); 
                                this.SetDataGrid(lst); 
                                this._urlList = lst; 
                            }