Am Mon, 15 Dec 2008 10:18:28 -0800 schrieb johnf <jfabi...@yolo.com>:
> 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 _______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor