Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ruby-style string interpolation in AppleScript

Is there a way to achieve Ruby-style, string interpolation in AppleScript? I need a flexible way of creating string patterns.

Ruby:

fn = "john"
=> "john"

ln = "doe"
=> "doe"

addresses = []
=> []

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

addresses << "#{fn}.#{ln}@company.com"
=> ["[email protected]", "[email protected]"]

AppleScript:

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

set theAddresses to {}

# [email protected]
copy [something here] & "@company.com" to the end of theAddresses
like image 842
craig Avatar asked Jan 25 '14 18:01

craig


1 Answers

AFAIK there's no string interpolation in AppleScript. The equivalent would be something like this:

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

# {"[email protected]", "[email protected]"}
like image 118
Stefan Avatar answered Oct 06 '22 20:10

Stefan