使 AppleScript 区分大小写
Make AppleScript Case-Sensitive
在下面的脚本中,
set theText to "ASDF"
set lowercase to "abcdefghijklmnopqrstuvwxyz"
set numeric to "0123456789"
set containsLowercase to false
set containsUppercase to false
set containsNumber to false
set containsSomethingElse to false
repeat with theCharacter in theText
if lowercase contains theCharacter then
set containsLowercase to true
else if uppercase contains theCharacter then
set containsUppercase to true
else if numeric contains theCharacter then
set containsNumber to true
else
set containsSomethingElse to true
end if
end repeat
if containsLowercase and (containsNumber or containsSomethingElse) then
if containsNumber and containsSomethingElse then
say "The text contains a mix of lowercase, numbers, and something else."
else if containsNumber then
say "The text contains a mix of lowercase and numbers."
else
say "The text contains a mix of lowercase and something non-numeric."
end if
else if containsLowercase then
say "The text contains only lowercase characters."
else if containsNumber and containsSomethingElse then
say "The text contains a mix of numbers and something non-alphabetic."
else if containsNumber then
say "The text contains only numbers."
else if containsSomethingElse then
say "The text contains only non-numeric and non-alphabetic characters."
else
say "I think there is something wrong with my logic, Dave."
end if
即使 theText 只是大写字母,它仍然认为它包含用变量 lowercase 定义的小写字母表。 我在某处读到 AppleScript 不区分大小写。我不确定这是否可行,但我希望它区分大小写。有什么办法吗?
您可以使用 "considering" 语句。
considering case
if theAlphabet contains theCharacter then
set containsLowerAlpha to true
end if
if theUpperAlphabet contains theCharacter then
set containsUpperAlpha to true
end if
end considering
More about considering at the Apple documentation for control statements.
在下面的脚本中,
set theText to "ASDF"
set lowercase to "abcdefghijklmnopqrstuvwxyz"
set numeric to "0123456789"
set containsLowercase to false
set containsUppercase to false
set containsNumber to false
set containsSomethingElse to false
repeat with theCharacter in theText
if lowercase contains theCharacter then
set containsLowercase to true
else if uppercase contains theCharacter then
set containsUppercase to true
else if numeric contains theCharacter then
set containsNumber to true
else
set containsSomethingElse to true
end if
end repeat
if containsLowercase and (containsNumber or containsSomethingElse) then
if containsNumber and containsSomethingElse then
say "The text contains a mix of lowercase, numbers, and something else."
else if containsNumber then
say "The text contains a mix of lowercase and numbers."
else
say "The text contains a mix of lowercase and something non-numeric."
end if
else if containsLowercase then
say "The text contains only lowercase characters."
else if containsNumber and containsSomethingElse then
say "The text contains a mix of numbers and something non-alphabetic."
else if containsNumber then
say "The text contains only numbers."
else if containsSomethingElse then
say "The text contains only non-numeric and non-alphabetic characters."
else
say "I think there is something wrong with my logic, Dave."
end if
即使 theText 只是大写字母,它仍然认为它包含用变量 lowercase 定义的小写字母表。 我在某处读到 AppleScript 不区分大小写。我不确定这是否可行,但我希望它区分大小写。有什么办法吗?
您可以使用 "considering" 语句。
considering case
if theAlphabet contains theCharacter then
set containsLowerAlpha to true
end if
if theUpperAlphabet contains theCharacter then
set containsUpperAlpha to true
end if
end considering
More about considering at the Apple documentation for control statements.