Page 1 of 1
String Substitution
Posted: Sat Jan 23, 2016 4:20 pm
by skelbone
Hi guys, I'm wondering how to perform a string substitution in livecode. Is this the way it's done? I need to make the value of the variable part of a string.
Code: Select all
local vSeason
local tSearch
put "Summer time" into vSeason
put "Things are always hot during vSeason" into tSearch
Any ideas. I'd really appreciate it. Thanks
Re: String Substitution
Posted: Sat Jan 23, 2016 4:38 pm
by Thierry
skelbone wrote:need to make the value of the variable part of a string.
Any ideas.
You can try one of these:
Code: Select all
put "Summer time" into vSeason
put "tSearch1: " & "Things are always hot during " & vSeason
Code: Select all
put "tSearch2: " & merge( "Things are always hot during [[vSeason]]")
Code: Select all
put "tSearch3: " & format( "Things are always hot during %s", vSeason )
and check in the Dictionary for merge() and format()
HTH,
Thierry
Re: String Substitution
Posted: Sat Jan 23, 2016 4:45 pm
by skelbone
Thanks Thierry, the merge worked fine, but I suspect the 'format' version will work well too.
Thank you very much.
Re: String Substitution
Posted: Sat Jan 23, 2016 5:23 pm
by Dixie
Hi...
Your script...
Code: Select all
local vSeason
local tSearch
put "Summer time" into vSeason
put "Things are always hot during vSeason" into tSearch
put tSearch
if you run this it will return vSeason...
run this to return "Things are always hot during Summer time"
Code: Select all
local vSeason
local tSearch
put "Summer time" into vSeason
put "Things are always hot during" && vSeason into tSearch
put tSearch
see the difference ?
Thierry's method is the one that I think you are after...
