首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

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

2012-03-16 
怎样提取TextBox里面的数字?如题:怎样提取TextBox里面的数字?别的控件需要“引用提取出来的值”,如何实现?请

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

热点排行