Page 1 of 1

Newbie: Chunks..reg. expressions?

Posted: Fri Jun 08, 2007 2:16 am
by kpeters
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

Re: Newbie: Chunks..reg. expressions?

Posted: Fri Jun 08, 2007 8:00 am
by Mark Smith
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

Posted: Fri Jun 08, 2007 5:45 pm
by kpeters
Thanks once again, Mark,

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

Cheers,
Kai