使AppleScript区分大小写

时间:2015-05-25 17:40:35

标签: 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只是大写字母,它仍然认为它包含用变量小写字母定义的小写字母。我在某处读到了AppleScript不区分大小写的地方。我不确定这是否可行,但我希望它区分大小写。有办法吗?

1 个答案:

答案 0 :(得分:1)

您可以使用“考虑”声明。

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.