"john" ln = "doe" => -6ren">
gpt4 book ai didi

AppleScript 中的 Ruby 风格字符串插值

转载 作者:数据小太阳 更新时间:2023-10-29 06:59:56 24 4
gpt4 key购买 nike

有没有办法在 AppleScript 中实现 Ruby 风格的字符串插值?我需要一种灵活的方式来创建字符串模式。

ruby :

fn = "john"
=> "john"

ln = "doe"
=> "doe"

addresses = []
=> []

addresses << "#{fn[0]}#{ln}@company.com"
=> ["jdoe@company.com"]

addresses << "#{fn}.#{ln}@company.com"
=> ["jdoe@company.com", "john.doe@company.com"]

苹果脚本:

set fn to "john"
set ln to "doe"

set theAddresses to {}

# jdoe@company.com
copy [something here] & "@company.com" to the end of theAddresses

最佳答案

据我所知,AppleScript 中没有字符串插值。等效的是这样的:

copy first character of fn & ln & "@company.com" to the end of theAddresses
copy fn & "." & ln & "@company.com" to the end of theAddresses

# {"jdoe@company.com", "john.doe@company.com"}

关于AppleScript 中的 Ruby 风格字符串插值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21354338/

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