读书人

怎样提取TextBox里面的数字?解决方案

发布时间: 2012-03-16 16:34:56 作者: rapoo

怎样提取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"
}

读书人网 >asp.net

热点推荐