1
如何將AppleScript中用戶輸入的句子變爲每個單詞的單獨變量。例如,Lorem ipsum dolor sit amet
會被空格分成不同的變量,例如。 var1 = lorem, var2 = ipsum
等。以下是我到目前爲止所提出的,但我顯然無法獲得。將字符串拆分爲多個變量AppleScript
set TestString to "1-2-3-5-8-13-21"
set myArray to my theSplit(TestString, "-")
on theSplit(theString, theDelimiter)
-- save delimiters to restore old settings
set oldDelimiters to AppleScript's text item delimiters
-- set delimiters to delimiter to be used
set AppleScript's text item delimiters to theDelimiter
-- create the array
set theArray to every text item of theString
-- restore the old setting
set AppleScript's text item delimiters to oldDelimiters
-- return the result
return theArray
end theSplit