string a="荐  69,255.00 (53.10%) 搜   40,845.00 (31.32%) 直   20,320.00 (15.58%) ";如上字符串,如何分别提出()括号内的三个数值并存放在数组中?

解决方案 »

  1.   

    a.split('(',')')[1]a.split('(',')')[3]a.split('(',')')[5]
      

  2.   

    for (int i = 1; i <=5; i += 2)
        a.split('(',')')[n];
      

  3.   


    string a = "荐  69,255.00 (53.10%) 搜   40,845.00 (31.32%) 直   20,320.00 (15.58%) ";
                string Att = null;
                while (a.Contains('%'))
                {
                     Att = Att+","+a.Substring(a.IndexOf("(") + 1, a.IndexOf("%") - a.IndexOf("("));
                    a = a.Substring(a.IndexOf(")")+1);
                }
               string [] arr= Att.Trim(',').Split(',');
    O(∩_∩)O哈哈~
      

  4.   


                String a = "荐  69,255.00 (53.10%) 搜   40,845.00 (31.32%) 直   20,320.00 (15.58%) ";
                MatchCollection matches = Regex.Matches(a, @"\(([^\)]*?)\)");
                String[] arr = new String[matches.Count];
                for(int i=0;i<matches.Count;i++)
                {
                    arr[i] = matches[i].Groups[1].Value;
                }
                foreach (String s in arr)
                {
                    Console.WriteLine(s);
                }
      

  5.   

    substring和split都可以的。        string a = "荐  69,255.00 (53.10%) 搜   40,845.00 (31.32%) 直   20,320.00 (15.58%) ";
           
            string[] aa = a.Split('(', ')');
            ArrayList li = new ArrayList(aa);
            for (int i = 0; i < li.Count; i++)
            {
                if (!li[i].Equals("%"))
                {
                    li.Remove(li[i]);
                }
            }
            aa = (string[])li.ToArray(typeof(string));
            for (int i = 0; i < aa.Length; i++)
            {
                Response.Write("aa==" + aa[i] + "<br>");
            }