检查字符串是否为数字的最佳方法 [英] Best way to check if string is numeric

查看:90
本文介绍了检查字符串是否为数字的最佳方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个字符串字段和十进制字段,并且想知道什么是最好的

检查数字的方法是什么?


我必须做点什么喜欢:


如果(myAmount是数字)

{

总计+ = myAmount;

}


谢谢,


Tom

解决方案

使用Decimal.Parse或TryParse。

所有数值数据类型都可能包含Parse& TryParse。


Kalpesh


12月18日上午11:02,tshad < t ... @ dslextreme.comwrote:


我有一个字符串字段和一个十进制字段,想知道什么是最好的

检查数字的方法是什么?


我必须做类似的事情:


如果(myAmount是数字)

{

总计+ = myAmount;


}


谢谢,

汤姆


不知道是否最好,但你不能沿着这条线路上的东西


private static Rage _isNumber = new Rage(@" ^ \d +


");


public static bool IsInteger (字符串theValue)

{

匹配m = _isNumber.Match(theValue);

返回m.Success;

} // IsInteger


" tshad" < tf*@dslextreme.com写在消息中

新闻:uG ************** @ TK2MSFTNGP05.phx.gbl ...


我有一个字符串字段和一个十进制字段,并且想知道什么是最好的

检查数字的方法是什么?


我必须做类似的事情:


如果(myAmount是数字)

{

total + = myAmount; < br $>
}


谢谢,


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...@dslextreme.comwrote:

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*@dslextreme.comwrote 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



这篇关于检查字符串是否为数字的最佳方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆