具有字符串ArrayList的IsNumber [英] IsNumber with a String ArrayList

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

问题描述

我想知道如何识别整个字符串(如果它是数字),而不是每个数字(使用索引).

示例:

字符串号="-1.234";

char.IsNumber(number,0); //输出= FALSE

因为-不是数字,但是如果我将其检查为整数,则它将为TRUE ...

还有其他不使用索引的方法吗?

I want to know how to identify a whole string if it is a Number, instead of each digit (using the index).

Example:

string number = "-1.234";

char.IsNumber( number, 0 ); //Output = FALSE

Because the - is not a number, but if I check it as a whole number then it will be TRUE...

Any other way to do not use the index?

推荐答案

可以使用Decimal.TryParse吗?
Could you use Decimal.TryParse?


我认为,您想要像这样
I think, you want like this
string number = "-1.234";
            double test = 0;

            if (double.TryParse(number,out test) && test >= 0)
                MessageBox.Show("Yes");
            else
                MessageBox.Show("No");


查看 Int32.TryParse方法 [ ^ ]和Double.TryParse方法 [
Look at the Int32.TryParse Method[^] and Double.TryParse Method[^]: they returns true if the string content represents an int or a double respectively, and false otherwise.


这篇关于具有字符串ArrayList的IsNumber的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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