String search

Bruno Desthuilliers bruno.42.desthuilliers at websiteburo.invalid
Fri Feb 27 11:15:25 CET 2009


pranav a écrit :
> Greeting fellow pycoders,
> 
> I have a script that browses large codes and replaces certain text
> with some other text. Of lately i observed an issue.Some of the
> original text were like
> 
> <cfif IsDefined("attributes.SOFTPREREQ")>
>     ,N'#attributes.SOFTPREREQ#'
> </cfif>
> 
> My module does scan this code and suggests replacement to this code.
> But when i use the string.replace() method, it just fails. A
> string.find() for above code in the whole file returns code -1.
> Where am i going wrong? 

Not posting a minimal (and if possible runnable) excerpt of your code 
exhibiting the problem, along with test data.

>I figure it could be something to do with
> character encoding or else.

or with white spaces (including newlines characters), or whatever.

As a general guideline : any non-trivial text parsing requires a 
non-trivial parser.



More information about the Python-list mailing list