在 MS SQL SERVER 2005数据库中的一张表中的某一字段记录如下内容:
172.168.1.1|172.168.1.2|172.168.1.3|172.168.1.4|
怎样取各个IP地址字符串,它们是以 竖杠分隔的。

解决方案 »

  1.   

    参考Split
      

  2.   

    string str = "172.168.1.1|172.168.1.2|172.168.1.3|172.168.1.4|";
    string[] strs = str.Split('|');
    foreach( string key in strs )
    {
    MessageBox.Show(key);
    }

    你的问是我解决了,点击转到我的问题了,谢谢进来!
      

  3.   

    string queryString =
            "SELECT IPs  FROM tablename";
     
        using (SqlConnection connection =
                   new SqlConnection(connectionString))
        {
            SqlCommand command =
                new SqlCommand(queryString, connection);
            connection.Open();
     
            SqlDataReader reader = command.ExecuteReader();
           reader.Read();
            string[] ips = str.Split('|');//数组中即是你要的分割好的ip                    
     
            reader.Close();
    }
      

  4.   

    ....
      string[] ips = reader[0].ToString().Split('|');
    ....
      

  5.   

    string str = "172.168.1.1|172.168.1.2|172.168.1.3|172.168.1.4|";
                string[] strs = str.Split('|');
                foreach( string key in strs )
                {
                    MessageBox.Show(key);
                }