Easier way to do this? Find variables in text

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: Klaus, FourthWorld, heatherlaine, kevinmiller

kaveh1000
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 334
Joined: Sun Dec 18, 2011 7:23 pm
Location: London
Contact:

Re: Easier way to do this? Find variables in text

Post by kaveh1000 » Mon May 06, 2019 12:27 pm

Here is a minimal stack that does the job using regex
Attachments
extract.zip
(1.21 KiB) Downloaded 15 times
Kaveh

Thierry
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 651
Joined: Wed Nov 22, 2006 3:42 pm
Location: France
Contact:

Re: Easier way to do this? Find variables in text

Post by Thierry » Mon May 06, 2019 2:57 pm

kaveh1000 wrote:
Mon May 06, 2019 12:27 pm
Here is a minimal stack that does the job using regex

Hi Kaveh,

If you don't mind,
here is a slightly optimized and less verbose version of your code:

Code: Select all

   on mouseup
   local tOriginal, tResult
   put fld "Original" into tOriginal

   repeat forever
      if not matchChunk(tOriginal, "@{(.+?)}", tStart, tEnd) then exit repeat
      put char tStart to tEnd of tOriginal & cr after tResult
      delete char 1 to tEnd of tOriginal
   end repeat

   delete last char of tResult
   put tResult into fld "Result"
end mouseup
Regards,

Thierry
Thierry Douez - https://sunny-tdz.com
Pourquoi tant de notes lorsqu'il suffit de jouer les plus belles... [Barbara]

kaveh1000
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 334
Joined: Sun Dec 18, 2011 7:23 pm
Location: London
Contact:

Re: Easier way to do this? Find variables in text

Post by kaveh1000 » Mon May 06, 2019 3:20 pm

Wonderful. Much better. Thanks Thierry. :-) Easier to read too!!
Kaveh

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”