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: FourthWorld, heatherlaine, Klaus, kevinmiller

kaveh1000
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 508
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 144 times
Kaveh

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

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

kaveh1000
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 508
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”