日期:2014-05-17 浏览次数:20474 次
string s = "aa,1;aa,2;aa,3;bb,4;bb,5;cc,6;dd,7;dd,8"; string[] parts = Regex.Split(s, @"(?:^|;)\w+,"); string result = string.Join(",", parts).Trim(','); Response.Write(result);
------解决方案--------------------
string s ="aa,1;aa,2;aa,3;bb,4;bb,5;cc,6;dd,7;dd,8;"; StringBuilder sb = new StringBuilder(); string[] ss = s.Split(';'); foreach(string s in ss) { sb.Append(s.Split(',')[1]+","); } Response.Write(sb.ToString.TrimEnd(','));
------解决方案--------------------
或者这样也行:
string s = "aa,1;aa,2;aa,3;bb,4;bb,5;cc,6;dd,7;dd,8"; string result = Regex.Replace(s, @";?\w+,", ",").Trim(','); Response.Write(result);
------解决方案--------------------
string s = "aa,1;aa,2;aa,3;bb,4;bb,5;cc,6;dd,7;dd,8"; MatchCollection mc = Regex.Matches(s, @"\w+,(\d+)"); string s1 = ""; foreach (Match m in mc) { s1 += m.Groups[1].Value + ","; } Response.Write(s1.TrimEnd(','));//1,2,3,4,5,6,7,8