检查字符串是否为数字的最佳方法

编程入门 行业动态 更新时间:2024-10-21 05:39:27
本文介绍了检查字符串是否为数字的最佳方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个字符串字段和十进制字段,并且想知道什么是最好的 检查数字的方法是什么? 我必须做点什么喜欢: 如果(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

更多推荐

检查字符串是否为数字的最佳方法

本文发布于:2023-10-14 22:16:37,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1492372.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:字符串   数字   方法

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!