C#连接字符串,list中字符串添加逗号连接,连接字符串,分割字符串

List list_id = new List();
            if (this.datagridview1.Rows.Count > 0)
            {
                for (int i = 0; i < this.datagridview1.Rows.Count; i++)
                {
                    DataGridViewCheckBoxXCell checkCell = (DataGridViewCheckBoxXCell)this.datagridview1.Rows[i].Cells[0];
                    Boolean flag = Convert.ToBoolean(checkCell.Value);
                    if (flag)
                    {
                        list_id.Add("'" + this.datagridview1.Rows[i].Cells[1].Value.ToString() + "'");
                    }
                }
            }
            string str1 = string.Join(",", list_id.ToArray());
            if (!string.IsNullOrEmpty(str1))
            {

                 DataTable data = this.dClass.GetDataTable(string.Concat(new object[]                     
                  { "SELECT* FROM  Rx_xiao where ddhao in (", str1, ")" }));
            }






StringBuilder MyStringBuilder = new StringBuilder(); ;
MyStringBuilder.Append("不存在,请检查  ");
MyStringBuilder.Append(data.Rows[i][0]);
MyStringBuilder.Append("\n");
MessageBox.Show(MyStringBuilder.ToString());

1、用字符串分隔:

using System.Text.RegularExpressions;
string str="aaajsbbbjsccc";
string[] sArray=Regex.Split(str,"js",RegexOptions.IgnoreCase);
foreach (string i in sArray) Response.Write(i.ToString() + "
");

 输出结果:
aaa
bbb
ccc
 

2、用多个字符来分隔:

string str="aaajbbbscccjdddseee";

string[] sArray=str.Split(new char[2]{'j','s'}); 
foreach(string i in sArray) Response.Write(i.ToString() + "
");


 输出结果:
aaa
bbb
ccc
ddd
eee
 
3、用单个字符来分隔:

string str="aaajbbbjccc";
string[] sArray=str.Split('j');
foreach(string i in sArray) Response.Write(i.ToString() + "
")


  输出结果:
aaa
bbb

   ccc

 

 

你可能感兴趣的:(字符串)