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:

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

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

Now if I want to remove :

substr = ""
${if:isLeaf}
  Dont include this isLeaf=True
${/if:isLeaf}
"""

Expected output is :

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

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

Actual Output:

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

Note: See additional newlines before isStatic tag


Any Suggestions ?

This works just as expected ...

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

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

substr = """
${if:isLeaf}
  Dont include this isLeaf=True
${/if:isLeaf}
"""

print mainstr.replace(substr, "")

""" result =

${if:isStatic}
  include this isStatic=True
${/if:isStatic}
"""
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.