str = "92349"
n = str as integer
if (n != undefined) then ...
在不使用 Execute() 的情况下,MAXScript 中是否有更好的方法来确定字符串是否代表数字(或不代表数字)?
You can also try dotnet within max like so:
local pstring = "12"
local res = false
local parseRes = (dotnetclass "System.Int32").TryParse pstring &res
if parseRes do
(
print res
)
您的 .net 解决方案非常酷。但是为什么要避免在一行中使用 mxs 简单的方式
fn isInteger str = isKindOf (str as number) integer
只是为了扩展接受的答案,最好这样做,因为 maxscript 解释各种数字类型的方式,因为它们中有一个字母。因此,以下所有情况都会产生一个数字:
" " as number --> 0
"." as number --> 0.0
"L" as number --> 0L
"P" as number --> 0P
"f" as number --> 0f
"m" as number --> 0f
"t" as number --> 0f
或这些的变体:
"ft" as number --> 0f
"fd0" as number --> 0f
"te0" as number --> 0f
"f00m" as number --> 0f
"m.f.t." as number --> 0f
etc.
大多数时候你会得到零——但并非总是如此,请注意这个序列(ASCII 185、178、179):
"¹" as number --> 137
"²" as number --> 130
"³" as number --> 131