使用 applescript 获取字符串的前几个字符

Getting first few characters of a string with applescript

我希望在 applescript 中只保留字符串的前 13 个字符。我想我不明白如何使用 "characters" 函数。 有人可以帮助我吗?

choose from list {"0041325677667-pharmacie 1", "0041325677557-pharmacie 2",
"0041325677447-pharmacie 3", "0041325677337-pharmacie 4"} with prompt 
"Thanks to select" without multiple selections allowed and empty selection allowed 
return the result as string 
return characters 1 thru 13 of result

在此先感谢您的帮助

characters x thru y returns 字符列表,在您的示例项目 1 returns

{"0", "0", "4" ,"1" ,"3" ,"2" ,"5" ,"6" ,"7" ,"7" ,"6" ,"6", "7"}

text x thru y return请求的字符串。

without multiple selections allowed and empty selection allowed 是默认值,因此可以省略。但是你应该考虑用户按下 "Cancel" 时的情况,然后表达式 return boolean false.

set chosen to choose from list {"0041325677667-pharmacie 1", "0041325677557-pharmacie 2", "0041325677447-pharmacie 3", "0041325677337-pharmacie 4"} with prompt "Thanks to select"
if chosen is false then return "" -- in case of 'Cancel' return empty string
return text 1 thru 13 of (item 1 of chosen) -- as chosen returns a list by default it must be flattened