一个字符串转换成数组5个一组
protected void Page_Load(object sender, EventArgs e) { string sql = "a|b|c|d| | |e|f|g|h|i|j|k"; System.Text.RegularExpressions.Regex ze = new System.Text.RegularExpressions.Regex("\\s"); sql= ze.Replace(sql,""); System.Text.RegularExpressions.Regex ze1 = new System.Text.RegularExpressions.Regex("|"); sql = ze.Replace(sql, "|"); string[] dd = { "|" }; string[] aa = sql.Split(dd, StringSplitOptions.RemoveEmptyEntries); int len = aa.Length; int x2=0; if(len%5==0) { x2=len/5; } else { x2=len/5+1; } int x = 0; string[] l = new string[x2]; for (int i = 0; i < len; i++) { if (i != 0 && i % 5 == 0) { x += 1; } l[x] += aa[i] + ","; } string q = ""; for (int i = 0; i < l.Length; i++) { q += l[i] + "<br/>"; } Response.Write(q); }