Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

editor.replace can't find ; character

Help
2012-05-31
2013-01-25
  • L&E Destock
    L&E Destock
    2012-05-31

    Hi,

    I try to replace a sentence with another both including some     ;   character inside but it doesn't work , when I delete that character then the script works but I need that character to be included.

    Here is the code I use :

    editor.replace("\"Parent";"- bad_br7001";"\"", "\"Parent";"bad_br7001";"TU\"")

    I'd like to replace
    >        "Parent";"- bad_br7001";""

    by that >   "Parent";"- bad_br7001";"TU"

    thanks for your help

     
  • It's not the ; that's the problem, it's the quote immediately before it.  You need to escape every quote that's in your string, or, because Python is great, you can just use a single quote, and then you don't need to escape your double quotes.

    So, easiest:

    editor.replace('"Parent";"- bad_br7001";""', '"Parent";"bad_br7001";"TU"')
    

    or, to correct your version:

    editor.replace("\"Parent\";\"- bad_br7001\";\"\"", "\"Parent\";\"bad_br7001\";\"TU\"")
    

    You can see from the syntax highlighting that it thinks the string is ended before the semi-colon, because the semi colon is coloured differently.

    Cheers,
    Dave.