如题:怎样提取TextBox里面的数字?
别的控件需要“引用提取出来的值”,如何实现?
请教高手!

解决方案 »

  1.   

    也就是说,当我在TextBox控件内输入了“我是83年的”后,我要提取里边的"83",保留不动,怎样进行这样的转换呢??
      

  2.   

    using System.Text.RegularExpressions;.........string str1 = TextBox.Text; //源字符串,如:“我是83年的”
    string str2 = @"\d+"; //正则表达式,匹配数字串的MatchCollection Matches = Regex.Matches(str1, str2);foreach (Match NextMatch in Matches)
    {
      string num = NextMatch.Value;
      //可以取出字符串中的数字,如果字符串中有多个如"aa11bb23"那么可以循环取出"11"和"22"
    }
      

  3.   


    foreach (Match NextMatch in Matches) 

      string num += NextMatch.Value; 
      //可以取出字符串中的数字,如果字符串中有多个如"aa11bb23"那么可以循环取出"11"和"22" 
    }