comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Re: Escaped Characters in string output
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
Re: Escaped Characters in string output [message #81536] Tue, 25 September 2012 22:11
M. Katz is currently offline  M. Katz
Messages: 69
Registered: May 2005
Member
Very elegant. Thanks!
Re: Escaped Characters in string output [message #81543 is a reply to message #81536] Tue, 25 September 2012 03:35 Go to previous message
Heinz Stege is currently offline  Heinz Stege
Messages: 189
Registered: January 2003
Senior Member
On Mon, 24 Sep 2012 20:13:06 -0700 (PDT), M. Katz wrote:

> To prepare string data for a database, I'd like to escape all of the special characters. Other languages have built-in functions for this. Does IDL, or someone from the community have a routine they trust?
>
> The special characters are
>
> \ ' " NUL (ASCII 0) \n and \r and CTRL-Z
>
> In essence I'd like to create a function that searches for these and places a backslash in front of each occurrence. See mysql_real_escape_string() http://dev.mysql.com/doc/refman/5.0/en/mysql-real-escape-str ing.html in PHP. In principle I suppose this is a good task for Regular Expressions, but I'm not enough of an expert.
>
> Thanks

I don't know about any built-in routine within IDL. I would make use
of a conversion table. This may be more efficient than regular
expressions:

table=[bytarr(1,256),bindgen(1,256)]
table[0,[byte('\''"'),10b,13b,26b]]=(byte('\'))[0]

input='"abc" 123 \xyz ''aaa''a'
output=table[*,byte(input)]
output=string(output[where(output ne 0b)])
print,input,output,form='(a)'

Cheers, Heinz
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Re: read an irregularly structured ascii file.
Next Topic: Image astigmatism

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Wed Oct 08 15:17:38 PDT 2025

Total time taken to generate the page: 0.00812 seconds