Newbie: Chunks..reg. expressions?

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
kpeters
Posts: 112
Joined: Wed Mar 21, 2007 9:32 pm

Newbie: Chunks..reg. expressions?

Post by kpeters » Fri Jun 08, 2007 2:16 am

Hi,

I want to replace the equal signs in a SQL query string with "like" if the word following an equal sign ends in the SQL wildcard character "%".

So:

select * from addresses where lastname = "sm%" and firstname = "k%" and city = "london"

should turn into

select * from addresses where lastname like "sm%" and firstname like "k%" and city = "london"

What is an elegant way to achieve this in Transcript?

TIA,
Kai

Mark Smith
Posts: 179
Joined: Sat Apr 08, 2006 11:08 pm
Contact:

Re: Newbie: Chunks..reg. expressions?

Post by Mark Smith » Fri Jun 08, 2007 8:00 am

Off the top of my head:

Code: Select all

repeat with n = 1 to the number of words in tQuery
  if word n of tQuery is "=" AND char - 2 of word n+1 of tQuery is "%" then put "like" into word n of tQuery
end repeat
Best,

Mark

kpeters
Posts: 112
Joined: Wed Mar 21, 2007 9:32 pm

Post by kpeters » Fri Jun 08, 2007 5:45 pm

Thanks once again, Mark,

for a solution that is way more elegant than what I had written!

Cheers,
Kai

Post Reply