" & quote...

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

Post Reply
GuidoSarducci
Posts: 2
Joined: Wed Aug 07, 2019 11:27 pm

" & quote...

Post by GuidoSarducci » Wed Aug 07, 2019 11:46 pm

So, I'm working with what should be a simple piece of code - it strips data from a temporary holding space and cleans it for insertion into a database. Or not:

-- Prep for Date
repeat until line 1 of tData contains <td class="date">
delete line 1 of tData
end repeat

I haven't figured out how to "properly" escape those quotes, regardless of research and forum information. Of course, it appears that part of my problem may be the keyword "date" combined with & quote options that causes the problem.

What, pray tell, am I doing wrong?

SparkOut
Posts: 2947
Joined: Sun Sep 23, 2007 4:58 pm

Re: " & quote...

Post by SparkOut » Wed Aug 07, 2019 11:59 pm

Code: Select all

repeat until line 1 of tData contains "<td class=" & quote & "date" & quote & ">"
   delete line 1 of tData
   wait 0 milliseconds with messages
end repeat
should do the trick

GuidoSarducci
Posts: 2
Joined: Wed Aug 07, 2019 11:27 pm

Re: " & quote...

Post by GuidoSarducci » Thu Aug 08, 2019 12:07 am

Good one - solved the problem!

SparkOut
Posts: 2947
Joined: Sun Sep 23, 2007 4:58 pm

Re: " & quote...

Post by SparkOut » Thu Aug 08, 2019 8:24 am

A more robust solution, and a handy technique for you:
1) a function can make the quote handling easier

Code: Select all

function repQ pText,pQ
   replace pQ with quote in pText
   return pText
end repQ
You can do your typing and swap another character for a double quote to make it easier, in the example below, use ~ as if you were typing a double quote inside the literal string. The second parameter tells the function which character you used to be the fake quote

Code: Select all

   put repQ("<td class=~date~>","~") into tSearch
   repeat while tSearch is not in line 1 of tData and tData is not empty
      delete line 1 of tData
      wait 0 milliseconds with messages
   end repeat
2) The code as you had it would loop forever if the data did not contain the target string. This example will end the repeat if the data becomes empty. (Which would probably be just as bad for your program operation but still.)
The wait with messages is a line which gives the engine a moment of as near zero duration as possible but stops the repeat loop becoming blocking and your application unresponsive if there is a lot of data to chunk through.

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10320
Joined: Wed May 06, 2009 2:28 pm

Re: " & quote...

Post by dunbarx » Thu Aug 08, 2019 2:03 pm

Hypercard introduced the "quote" as a constant over 2000 years ago just for this purpose, that the syntactical requirement for quoted strings made it necessary to have a, er, quote available "outside" and apart from such strings.

"Tab" is a similar constant, but is not so intimately embedded into the syntactic structure of our beloved xTalk paradigm, and can be far more easily differentiated between the constant itself and the character created with a keypress.

Craig

cpuandnet
Posts: 32
Joined: Thu Jan 17, 2019 6:43 am

Re: " & quote...

Post by cpuandnet » Thu Aug 08, 2019 4:09 pm

If the end result is just to escape the quotes so you can insert it into a database, i find it would just be easier to use query placeholders and let LiveCode work it's magic. And it is safer since it would avoid SQL injections.

Code: Select all

...
put "INSERT INTO html_table (html_field) VALUES (:1)" into tQuery
revExecuteSQL tDatabaseID, tQuery, "tData"
...

Post Reply