gpt4 book ai didi

string - 将一个字符串拆分为多个变量 AppleScript

转载 作者:行者123 更新时间:2023-12-04 11:21:40 25 4
gpt4 key购买 nike

我如何将用户在 AppleScript 中输入的句子转换为每个单词的单独变量。例如,Lorem ipsum dolor sit amet将被空间分成不同的变量,例如。 var1 = lorem, var2 = ipsum等等。以下是我到目前为止的想法,但我显然一无所获。

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

最佳答案

只需使用“词”关键字。这是脚本的一个小例子:

set teststring to "1-2-3-5-8-13-21"
set Wordlist to words of teststring -- convert string to list of words

repeat with aword in Wordlist --loop through each word
log aword -- do what ever you need with aword
end repeat

关于string - 将一个字符串拆分为多个变量 AppleScript,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42127438/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com