【问题标题】:String comparision never evaluate true in Alfred字符串比较永远不会在 Alfred 中评估为真
【发布时间】:2015-09-25 13:56:37
【问题描述】:

我正在为 Alfred 工作流程编写脚本。但是,字符串比较永远不会评估为真。

脚本中的"{query}" 确实被替换为正确的ctext 值类型,我可以使用display dialog "{query}"display dialog class of "{query}" 来反对。

if "{query}" is equal to "a" then
    say "in the a case"
else
    say "in the else case"
end if

我也尝试过使用if "{query}" = "a" then,但结果仍然相同。

评估不断落入else声明。

我在写条件语句的时候指的是下面的文章。

http://computers.tutsplus.com/tutorials/if-and-if-else-applescript-conditional-statements--mac-45590

【问题讨论】:

  • 选中“双引号”和“反斜杠”复选框为AppleScript设置转义
  • @jackjr300 感谢您的 cmets。检查转义复选框后,评估仍然是错误的。

标签: applescript alfred


【解决方案1】:

不正常,用这个脚本调试一下,可能字符串中包含不可见字符。

set t to "{query}"
display dialog "The ID of 'a' is " & id of "a" --> the  id of a is  97
repeat with i in t -- check the id of every character in "{query}"
    display dialog "The ID of '" & i & "' is " & id of i
end repeat
if t is equal to "a" then
    say "in the a case"
else
    say "in the else case"
end if

【讨论】:

  • 是的,你是对的。 {query} 中的第一个字符是一个空字符,字符代码为32。您上面的代码对调试有效。谢谢。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2016-10-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-05-30
相关资源
最近更新 更多