检查是否变量是编号:AppleScript的 [英] Check if variable is number: Applescript
本文介绍了检查是否变量是编号:AppleScript的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我如何检查是否变量是多少?
How can I check if a variable is a number?
我想这样的:
set a to 5
if a is a number
display dialog "Yes! It's a number!"
end if
我也试过这code:
I've also tried this code:
set a to 5
if a is integer
display dialog "Yes! It's a number!"
end if
但不幸的是预期它不工作。
But unfortunately it doesn't work as expected.
推荐答案
类的是,如果你使用整数会失败
class of a is integer will fail if you use
set a to "5"
即使变量是一个数字,但作为文本输入,这是否正常工作。
This will work if even if the variable is a number but was entered as text.
set a to "5"
try
set a to a as number
display dialog "Yes! It's a number!"
end try
这篇关于检查是否变量是编号:AppleScript的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文