将文本附加到 Applescript 中的字符串
AppleScript 中的串联似乎不允许您轻松地将文本附加到字符串变量。我有以下行可以在大多数其他语言中使用:
repeat with thisRecpt in recipients of eachMessage
set recp to recp & "," & address of thisRecpt
end repeat
据我所知,这似乎在 AppleScript 中不起作用,因为您显然不能在同一行中使用 recp 变量。有没有更简单的方法可以将文本添加到变量的末尾,而不必在循环中使用两个变量?
谢谢!
It seems that the concatenation in AppleScript doesn't let you easily append text to a string variable. I have the following line that would work in most other languages:
repeat with thisRecpt in recipients of eachMessage
set recp to recp & "," & address of thisRecpt
end repeat
From what I can tell, this doesn't seem to work in AppleScript, as you cannot use the recp variable within the same line apparently. Is there any easier way of adding text to the end of a variable without having to use two variables within the loop?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
只要先将
recp
设置为某项,例如""
,您发布的代码就可以正常工作。但是,您将得到一个,
作为字符串中的第一个字符,这可能不是您想要的。相反,你可以这样做:
是的,它很难看,但它更有效,并且你只会在地址之间得到“,”。
The code you posted works fine as long as
recp
is set to something first, say""
. However, you'll then get a,
as the first character in your string, which is probably not what you want.Instead, you can do this:
Yes, it's ugly, but it's more efficient and you'll only get "," between addresses.
更短、更干净的方式:
Shorter and cleaner way to: