2015-09-25 80 views
0

我正在爲一個Alfred工作流編寫腳本。但是,字符串比較永遠不會評估爲真。字符串比較在Alfred中永遠不會評估爲真

腳本內的"{query}"確實會被替換,我可以正面使用display dialog "{query}"display dialog class of "{query}"正確ctext值類型。

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

enter image description here

+0

檢查「**雙引號**」和「** **反斜槓」複選框來設置的AppleScript – jackjr300

+0

逃逸@ jackjr300感謝您的意見。檢查轉義複選框後,評估仍然是錯誤的。 –

回答

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 
+0

是的,你是對的。 「{query}」中的第一個字符是一個空字符,其char代碼爲「32」。上面的代碼對於調試是有效的。謝謝。 –