Am Mon, 15 Dec 2008 12:43:46 -0800
schrieb johnf <[email protected]>:

> On Monday 15 December 2008 11:31:12 am Andreas Kostyrka wrote:
> > Am Mon, 15 Dec 2008 10:18:28 -0800
> >
> > schrieb johnf <[email protected]>:
> > > Hi,
> > > I have a string that I need to extract just the sql
> > > statement. The following is the string
> > > \000\000\000\000\000\000\000\000.\000\000\000\0000\000\000\000
> > >
> > > \000$\000\000\000\000\000(\000\000\000\000X\000\000\000\000\000,
> > > \000\000\000\000P\000\000\000\000\000Q\000\000\000\000\000R\000
> > > \000\000\000\000/\000\000\000�\000\000\000\000%����\000\000\000
> > > \000'����\000\000\000\000+brttyp\000�\000\000\000\000*SELECT
> > > Brttyp.ctrscode, Brttyp.cdescript, Brttyp.ctrstype,
> > > Brttyp.cstatus, Brttyp.lreqno, Brttyp.dcreate FROM  brttyp Brttyp
> > > WHERE Brttyp.ctrscode = ( ?gcKey1 )\000\000\000\000\000
> > > AMCONNECT\000\000\000\000\000) \000\000\000\000\000\000\000
> > > \000\000\000\000BR Transaction Code File\000
> > >
> > > How can I get rid of all the junk?
> > >
> > > I can find the '*' with str.find('*') but I can't use find '\000'
> > > to get to the end?
> >
> > str.find has an optional second parameter specifying the start
> > where to search:
> >
> > Given the above string as str, you can do:
> >
> > start_pos = str.find('*')
> > sql = None
> > if start_pos != -1:
> >     end_pos = str.find('\0', start_pos)
> >     if end_pos == -1:
> >         end_pos = len(str)
> >     sql = str[start_pos:end_pos]
> >
> > Andreas
> 
> Thanks I got it done just as you explained.  What was interesting was
> my editor showed '\x000'  and not '\000'  so I was always looking for
> the wrong thing.  I thought I was doing it wrong.   Then while
> re-reading the message I sent to this list I noticed the lack of the
> 'x'.  And sure enough that was the problem.  Thanks for your help.

Well \xHH is the hexadecimal notation, while \OOO is the octal
notation. The problem is that \x000 means the 00 byte followed the
character 0.

Andreas

> 
> 
> 
_______________________________________________
Tutor maillist  -  [email protected]
http://mail.python.org/mailman/listinfo/tutor

Reply via email to