怎么提取这样的字符串12*36=2 
分别提取 12 和 36 还有 2出来

解决方案 »

  1.   

     string ss="12*36=2";
                string[] str1 = ss.Split('*');
                string s36 = str1[0];
                string[] str2 = str1[1].Split('=');
                string s2 = str2[1];
                string s12 = str2[0];
      

  2.   

    参考spit(char[])也可以看看正则表达式
      

  3.   

    利用substring和indexof来取得*和=号的位置应该可以获取到
      

  4.   

    如果格式固定,直接Split就可以了string test = "12*36=2";
    string[] result = test.Split(new char[] { '*', '=' });
    foreach (string s in result)
    {
        richTextBox2.Text += s + "\n";
    }
     
      

  5.   

    string sText = "12*36=2";
    MatchCollection mc = Regex.Matches(sText,@"\d+");
    foreach (Match m in mc)
    {
        Console.WriteLine(m.Value);
    }
      

  6.   

    /********Example*********/
    //要检测的字符串
    string str = "abc23*3=4 5*3=23";
    //存储匹配的字符串
    List<string> list = new List<string>();
    //要匹配的正则表达式
    System.Text.RegularExpressions.Regex regex = new System.Text.RegularExpressions.Regex(@"\d+\*\d+=\d+");
    //存储匹配的字符串到list
    if (regex.Matches(str).Count != 0)
    {
       for (int i = 0; i < regex.Matches(str).Count; i++)
       {
          list.Add(regex.Matches(str)[i].ToString());
       }
    }
    /*********Example*********/然后将list中字符串用*和=分割即可,如:string [] s = list[0].Split(new char[] { '*', '=' });
      

  7.   

    直接用正则匹配数字就可以了吧,顶多加上小数点
    [CODE LANGUAGE=C#]
    using System;
    using System.Text;
    using System.Text.RegularExpressions;namespace test{
        public class RegexTest{
            [STAThread]
            static void Main() {
                String input = "1.1*2=3.3*4.4=5";
                MatchCollection mc = Regex.Matches(input,@"(?<number>\d+(\.\d+)?)");
                foreach(Match m in mc){
                    Console.WriteLine(m.Result("${number}"));
                }
            }
        }
    }
    [/CODE]