[Tutor] Escape characters in strings

dman dsh8290@rit.edu
Sat, 5 Jan 2002 19:23:54 -0500


On Sat, Jan 05, 2002 at 06:28:49PM -0500, Grimmtooth wrote:
| 
| Is there a reliable way to catch backslashes in strings so that they don't
| get converted to escaped characters under some circumstances?

Are you eval()ing the strings?  If not then the interpreter doesn't do
any funny stuff with it.

| Example:
| 
| 12/13 14:04:53 2> S:<STX>L.TG23  Y1           12007030050020C100021340
| 12/13 14:04:53 2> S:12888888881003030000000001249000212011213140434210
| 12/13 14:04:53 2> S:10125414C200344012888888881=0512101543211234567800
| 12/13 14:04:53 2> S:1     700000000740   0242C00000000000000EN00420107
| 12/13 14:04:53 2> S:6O02450U300001000\300009990\000000000999\950U30000
| 12/13 14:04:53 2> S:1000\300002500\000000000250<ETX>.

Is this from a log file?  How are you reading the data?  Can you show
us the code?

| In the example, each case where '\300' occurs gets converted to an escaped
| character ('A' with a dot over it).  I've worked around this by
| pre-processing the raw string ( s = string.replace(s, '\300', '!300')) but
| it's a royal pain in the backside and could have ramifications I haven't
| forseen.

If you do want to eval() the string you can replace( "\\" , "\\\\" )
to escape all backslashes first.

HTH,
-D

-- 

How great is the love the Father has lavished on us,
that we should be called children of God!
        1 John 3:1