我有个一字符串:
a,b,c,d;e,f,g,h;b,d,s,a;s,f,g,h;
每组里面有四个字符串用“,”分开  每组之间用“;”分开 有n组
我现在要获取每组的 最后一个“‘”和“;”之间的字符串怎么截取啊 ?
比如 上面的我想要的结果是  d;h;a;h;
请大家帮忙!

解决方案 »

  1.   


    void Main()
    {
     string str="a,b,c,d;e,f,g,h;b,d,s,a;s,f,g,h;";
     foreach(Match m in Regex.Matches(str,@"(?<=,)[^,;]+?;"))
     {
     Console.WriteLine(m.Value);
    }

    /*
    d;
    h;
    a;
    h; */
    }
      

  2.   

    string source = "a,b,c,d;e,f,g,h;b,d,s,a;s,f,g,h;";
    string[] ss = source.Split(new char[]{';'});
    string temp;
    int index;
    for(int i = 0; i < ss.Length - 1; i++)
    {
        index= ss[i].LastIndexOf(",");
        temp += ss[i].SubString(index + 1);
    }
      

  3.   


    void Main()
    {
     string str="a,b,c,d;e,f,g,h;b,d,s,a;s,f,g,h;";
     str=Regex.Replace(str,@"[^,;]+?,","");
     Console.WriteLine(str); 

    /*
    d;h;a;h;
    */
    }
      

  4.   


    string str = "a,b,c,d;e,f,g,h;b,d,s,a;s,f,g,h;";            string resultStr = string.Empty;            string[] strAll = str.Split(';');
                for (int i = 0; i < strAll.Length - 1; i++)
                {
                    resultStr += strAll[i].Substring(strAll[i].Length - 1, 1);
                }            Response.Write(resultStr);
      

  5.   

    先分组
    str="a,b,c,d;e,f,g,h;b,d,s,a;s,f,g,h;";
    string aa[]=str.Split(';');
    然后取每组的最后一个字符
    string result="";
    for(int i=0;i<aa.Length;i++)
    {
      result+=aa[i].Substring(aa[i].Length-1);
    }