AppleScript中的Ruby样式字符串插值

前端之家收集整理的这篇文章主要介绍了AppleScript中的Ruby样式字符串插值前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
有没有办法在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"]

AppleScript的:

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

set theAddresses to {}

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

解决方法

AFAIK 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"}
原文链接:https://www.f2er.com/ruby/268209.html

猜你在找的Ruby相关文章