日期:2014-05-17  浏览次数:20474 次

字符串拆分的问题,,,,新学,,,求大侠帮助,,,急,,,
比较长的字符串="aa,1;aa,2;aa,3;bb,4;bb,5;cc,6;dd,7;dd,8;....";

如何拆分,将每一组(冒号之间的,如:aa,1)逗号前面的内容去掉,将每一组逗号后面的内容重新组合成一个字符串,如:1,2,3,4,5,6,....



新手求大侠们帮忙,,,急,,,

大热天的急的一身汗,,,,没弄出来,,,

------解决方案--------------------
你每一组之间的不是冒号啊,命名是分号,可以这样:
C# code
        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);

------解决方案--------------------
探讨
你每一组之间的不是冒号啊,命名是分号,可以这样:

C# code

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(",",……

------解决方案--------------------
C# code

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(','));

------解决方案--------------------
或者这样也行:
C# code
        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);

------解决方案--------------------
探讨
你每一组之间的不是冒号啊,命名是分号,可以这样:

C# code

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(",",……

------解决方案--------------------
C# code

           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