string s="1000-7,1200-15,1500-30"   
一个分成1000,1200,1500另外一个分成7,15,30

解决方案 »

  1.   

    先以 ' split
    再用 - split
      

  2.   


    arrlist=s.Split(',')
    for(int i=0;i<arrlist.length;i++)
    arr1[i]=arrlist[i].substring(0,4);
    arr1[i]=arrlist[i].substring(6,2);
      

  3.   


    string s = "1000-7,1200-15,1500-30";
            string[] s1 = s.Split(new char[2]{',','-'});
            int i = 0;
            foreach (var item in s1)
            {
                if (i%2==0)
                {
                    Response.Write(item + "<br>");
                }
                i++;
            }
      

  4.   

    string s = "1000-7,1200-15,1500-30";
    string[] arr= s.Split(new string[]{","},StringSplitOptions.RemoveEmptyEntries)
    foreach(string a in arr)
    {}
      

  5.   

    直接用正则取,然后保存list<int>
    手写的没测试
    string test = "1000-7,1200-15,1500-30";
    Regex reg = new Regex(@"(?<i>\d+)-(?<j>\d+)");
    MatchCollection mc = re.Matches(input);
    list<int> _i=new list<int>();
    list<int> _j=new list<int>();
    foreach (Match m in mc)
    {
    _i.Add(m.Groups["i"]);
    _j.Add(m.Groups["j"]);
    }