日期:2014-05-18  浏览次数:20508 次

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

------解决方案--------------------
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"
}