将 VB 的 Val 转换为 Java? [英] Convert VB's Val to Java?
问题描述
如何用Java编程语言实现VB的Val()函数或者有没有相同方法的API?
How to implement VB's Val() function using Java programming language or is there any API that has the same method?
推荐答案
你应该使用 Integer.parseInt
, Float.parseFloat
, Double.parseDouble
等 - 或 NumberFormat
取而代之,这取决于您是要以区分区域性的方式处理输入还是不是.
You should use Integer.parseInt
, Float.parseFloat
, Double.parseDouble
etc - or a NumberFormat
instead, depending on whether you want to treat the input in a culture-sensitive manner or not.
请注意,这些期望字符串包含数字而不是其他任何内容.如果您希望能够解析可能以数字开头然后包含其他位的字符串,则需要先清理字符串,例如使用正则表达式.
Note that these expect the string to contain the number and nothing else. If you want to be able to parse strings which might start with a number and then contain other bits, you'll need to clean the string up first, e.g. using a regular expression.
这篇关于将 VB 的 Val 转换为 Java?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!