问题描述
我正在阅读表格中的输入。我想验证输入是否确认
该字符串实际上是一个整数。我该怎么做?我是否需要
将其转换为角色阵列并分解每个角色并进行测试?
还是有更简单的方法吗?谢谢。
---
外发邮件经过认证无病毒。
由AVG反病毒系统检查(。
版本:6.0.720 /病毒库:476 - 发布日期:2004年4月14日
尝试执行Integer.parseInt(yourString),如果它抛出一个
NumberFormatException,你就会知道字符串isn' '有效整数
将字符串传递给parseInt并捕获NumberFormatException。
参见:
)
-
Gary
确定
尝试执行Integer.parseInt(yourString),如果它抛出一个
NumberFormatException,你就会知道字符串isn''ta有效整数
你真的是指整数吗?或者是数字。好的,那么你可以使用
Double.parseDouble(string);这将返回整数的结果,
浮点数和双打。
I am reading input from a form. I want to validate the input by making sure
that the string is actually an integer. How would I do this? Do i need to
convert it to a character array and break down each character and test it?
or is there an easier way? Thanks.
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.720 / Virus Database: 476 - Release Date: 7/14/04
Try to perform Integer.parseInt(yourString) and if it throws a
NumberFormatException you''ll know the string isn''t a valid integer
Hand the String to parseInt and catch NumberFormatException.
see:
http://java.sun.com/j2se/1.4.2/docs/...va.lang.String)
--
Gary
sure
Try to perform Integer.parseInt(yourString) and if it throws a
NumberFormatException you''ll know the string isn''t a valid integer
Do you really mean integer? Or is a "number" ok, then you can use
Double.parseDouble(string); which will return a result for integers,
floats, and doubles.
这篇关于测试字符串是否为整数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!