本文介绍了检查字符串是否为数字的最佳方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个字符串字段和十进制字段,并且想知道什么是最好的 检查数字的方法是什么? 我必须做点什么喜欢: 如果(myAmount是数字) { 总计+ = myAmount; } 谢谢, Tom
解决方案使用Decimal.Parse或TryParse。 所有数值数据类型都可能包含Parse& TryParse。 Kalpesh 12月18日上午11:02,tshad < t ... @ dslextremewrote: 我有一个字符串字段和一个十进制字段,想知道什么是最好的 检查数字的方法是什么? 我必须做类似的事情: 如果(myAmount是数字) { 总计+ = myAmount; } 谢谢, 汤姆
不知道是否最好,但你不能沿着这条线路上的东西 private static Rage _isNumber = new Rage(@" ^ \d +
"); public static bool IsInteger (字符串theValue) { 匹配m = _isNumber.Match(theValue); 返回m.Success; } // IsInteger " tshad" < tf*@dslextreme写在消息中 新闻:uG ************** @ TK2MSFTNGP05.phx.gbl ... 我有一个字符串字段和一个十进制字段,并且想知道什么是最好的 检查数字的方法是什么? 我必须做类似的事情: 如果(myAmount是数字) { total + = myAmount; } 谢谢, Tom
I have a string field and a decimal fields and was wondering what the best way to check for numeric is? I have to do something like: If (myAmount is numeric) { total += myAmount; } Thanks, Tom
解决方案 Use Decimal.Parse or TryParse. All the numeric datatype might have Parse & TryParse. Kalpesh On Dec 18, 11:02 am, "tshad" <t...@dslextremewrote: I have a string field and a decimal fields and was wondering what the best way to check for numeric is? I have to do something like: If (myAmount is numeric) { total += myAmount; } Thanks, Tom don''t know if the best but you cant ry something along the line of private static Rage _isNumber = new Rage(@"^\d+"); public static bool IsInteger(string theValue) { Match m = _isNumber.Match(theValue); return m.Success; } //IsInteger "tshad" <tf*@dslextremewrote in message news:uG**************@TK2MSFTNGP05.phx.gbl... I have a string field and a decimal fields and was wondering what the best way to check for numeric is? I have to do something like: If (myAmount is numeric) { total += myAmount; } Thanks, Tom
更多推荐
检查字符串是否为数字的最佳方法
发布评论