Removing a substring from a string

ankit ankitrastogi82 at gmail.com
Mon Jan 16 06:02:05 EST 2006


Hi All,
I want to remove a substring from a string without any additional
tabs/returns in the output string. Is there any method availaible or
how can I do it. For the ease, I am giving an example:

[code]
mainstr ="""
${if:isLeaf}
  Dont include this isLeaf=True
${/if:isLeaf}

${if:isStatic}
  include this isStatic=True
${/if:isStatic}

${if:!isLeaf}
   include this isLeaf=False
${/if:!isLeaf}
"""
[/code]

Now if I want to remove :
[code]
substr = ""
${if:isLeaf}
  Dont include this isLeaf=True
${/if:isLeaf}
"""
[/code]

Expected output is :
[code]
${if:isStatic}
  include this isStatic=True
${/if:isStatic}

${if:!isLeaf}
   include this isLeaf=False
${/if:!isLeaf}
[/code]

I am using mainstr.replace(substr, "") but it gives me additional
carriage returns which leads to empty spaces as follows:

Actual Output:
[code]





${if:isStatic}
  include this isStatic=True
${/if:isStatic}

${if:!isLeaf}
   include this isLeaf=False
${/if:!isLeaf}
[/code]

Note: See additional newlines before isStatic tag


Any Suggestions ?




More information about the Python-list mailing list