我想从文本中读取IP列表
IP后要跟端口,IP.TXT内容如下
127.0.0.1 80
127.0.0.2 21
127.0.0.3 22
.....
要多线程读取,怎样可以分别获取IP和端口两个参数呢
 private void ReadIPS()
  {
   StreamReader ss = File.OpenText ("ip.txt");      while (ss.Peek() != -1) 
  {
      this.ips.Add(ss.ReadLine());
  }
      ss.Close();
  }
这样只能获取到"127.0.0.1 80",我想把IP和端口分开啊

解决方案 »

  1.   

    用split(' ')分隔 127.0.0.1 80
      

  2.   

    string ipport="127.0.0.1 80";
    ip=ipport.Split(" ")[0];
    port=ipport.Split(" ")[1];
      

  3.   

    Split(" ") 错了,应该是(' ')
      

  4.   

       1. #region bool IsIPAddress(str1) 判断是否是IP格式   
       2. /**//// <summary>  
       3. /// 判断是否是IP地址格式 0.0.0.0  
       4. /// </summary>  
       5. /// <param name="str1">待判断的IP地址</param>  
       6. /// <returns>true or false</returns>  
       7. public static bool IsIPAddress(string str1)  
       8. {  
       9.     if(str1==null||str1==string.Empty||str1.Length<7||str1.Length>15) return false;   
      10.     string regformat = @"^\d{1,3}[\.]\d{1,3}[\.]\d{1,3}[\.]\d{1,3}$";  
      11.     Regex regex = new Regex(regformat,RegexOptions.IgnoreCase );  
      12.     return regex.IsMatch(str1);  
      13. }  
      14. #endregion  
      

  5.   


    正确,不过 Split(' ')是单引号
      

  6.   


    具体怎么写法呢?这样吗?有语法错误啊,
    private void ReadIPS() 
      { 
      StreamReader ss = File.OpenText ("ip.txt");       while (ss.Peek() != -1) 
      { 
          this.ips.Add(ss.ReadLine()); 
      } 
          ss.Close(); 
          string ipport = ips";
          ip = ipport.Split(' ')[0];
          port = ipport.Split(' ')[1];
      } 
    无法将类型“System.Collections.ArrayList”隐式转换为“string”
      

  7.   

    private void ReadIPS() 
      { 
      StreamReader ss = File.OpenText ("ip.txt");       while (ss.Peek() != -1) 
      { 
          this.ips.Add(ss.ReadLine()); 
      } 
          ss.Close(); 
       for(int index = 0; index < ips.Count; index++)
        {
          string ipport = ips[index] as string; 
          if(!string.IsNullOrEmpty(ipport))
          {
          ip = ipport.Split(' ')[0]; 
          port = ipport.Split(' ')[1]; 
          }
         }
      } 
      

  8.   


    还是错误,无法将类型“System.Collections.ArrayList”隐式转换为“string”
    是ip列表啊,是不是数据定义错啦