String Substitution

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
skelbone
Posts: 5
Joined: Tue Oct 22, 2013 10:18 pm

String Substitution

Post by skelbone » Sat Jan 23, 2016 4:20 pm

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
- skelbone
LiveCode 6.1.2 - Windows 7, AMD Athalon II Processor

Thierry
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 875
Joined: Wed Nov 22, 2006 3:42 pm

Re: String Substitution

Post by Thierry » Sat Jan 23, 2016 4:38 pm

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
!
SUNNY-TDZ.COM doesn't belong to me since 2021.
To contact me, use the Private messages. Merci.
!

skelbone
Posts: 5
Joined: Tue Oct 22, 2013 10:18 pm

Re: String Substitution

Post by skelbone » Sat Jan 23, 2016 4:45 pm

Thanks Thierry, the merge worked fine, but I suspect the 'format' version will work well too.
Thank you very much.
- skelbone
LiveCode 6.1.2 - Windows 7, AMD Athalon II Processor

Dixie
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1336
Joined: Sun Jul 12, 2009 10:53 am

Re: String Substitution

Post by Dixie » Sat Jan 23, 2016 5:23 pm

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... :-)

Post Reply