1
str = "92349"       
n = str as integer
if (n != undefined) then ...

在不使用 Execute() 的情况下,MAXScript 中是否有更好的方法来确定字符串是否代表数字(或不代表数字)?

4

3 回答 3

2

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
)

http://msdn.microsoft.com/en-us/library/f02979c7.aspx

于 2014-06-10T10:01:25.803 回答
0

您的 .net 解决方案非常酷。但是为什么要避免在一行中使用 mxs 简单的方式

fn isInteger str = isKindOf (str as number) integer
于 2014-08-25T21:14:07.567 回答
0

只是为了扩展接受的答案,最好这样做,因为 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
于 2016-05-12T11:40:37.960 回答