[英]How do I check if a string is a valid integer?
Let's say I have假设我有
val s = "123"
val r = "a123h"
How do I check if s
can be resolved to a valid integer?如何检查
s
可以解析为有效整数?
The signature of to-int
in the package core
is包
core
中to-int
的签名是
public lostanza defn to-int (s:ref<String>) -> ref<False|Int>
So you need :所以你需要:
defn is-int? (s: String) -> True|False :
to-int(s) is Int
NB: to-int
accepts hexadecimal 0x...
, octal 0o...
and binary 0b...
string representations in addition to decimal ones.注意:
to-int
接受十六进制0x...
、八进制0o...
和二进制0b...
除了十进制字符串表示。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.