Gio*_*gio 3 variables macos applescript numbers
如何检查变量是否为数字?
我正在尝试这个:
set a to 5
if a is a number
display dialog "Yes! It's a number!"
end if
Run Code Online (Sandbox Code Playgroud)
我也试过这段代码:
set a to 5
if a is integer
display dialog "Yes! It's a number!"
end if
Run Code Online (Sandbox Code Playgroud)
但不幸的是,它没有按预期工作.
小智 7
set a to 5
if class of a is integer then
display dialog "Yes! It's a number!"
end if
Run Code Online (Sandbox Code Playgroud)
如果你使用 a 的类是整数将会失败
set a to "5"
Run Code Online (Sandbox Code Playgroud)
即使变量是数字但作为文本输入,这也将起作用。
set a to "5"
try
set a to a as number
display dialog "Yes! It's a number!"
end try
Run Code Online (Sandbox Code Playgroud)