| | |
Removing a substring from a string
Please support our Python advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Aug 2005
Posts: 7
Reputation:
Solved Threads: 0
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:
Now if I want to remove :
Expected output is :
I am using mainstr.replace(substr, "") but it gives me additional carriage returns which leads to empty spaces as follows:
Actual Output:
Note: See additional newlines before isStatic tag
Any Suggestions ?
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:
Python Syntax (Toggle Plain Text)
mainstr =""" ${if:isLeaf} Dont include this isLeaf=True ${/if:isLeaf} ${if:isStatic} include this isStatic=True ${/if:isStatic} """
Now if I want to remove :
Python Syntax (Toggle Plain Text)
substr = "" ${if:isLeaf} Dont include this isLeaf=True ${/if:isLeaf} """
Expected output is :
Python Syntax (Toggle Plain Text)
${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:
Python Syntax (Toggle Plain Text)
${if:isStatic} include this isStatic=True ${/if:isStatic}
Note: See additional newlines before isStatic tag
Any Suggestions ?
This works just as expected ...
[php]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}
"""
[/php]
[php]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}
"""
[/php]
May 'the Google' be with you!
![]() |
Similar Threads
- Question about string pattern matching (Java)
- error creating substring (VB.NET)
- Removing found chars from string (C)
Other Threads in the Python Forum
- Previous Thread: Limiting the size of List
- Next Thread: Best way to convert C++ coding to Python
| Thread Tools | Search this Thread |
address anydbm app bash beginner changecolor cipher class clear conversion coordinates corners curves definedlines development dictionary dynamic events examples excel feet file float format function generator getvalue gui handling homework images import input ip java keycontrol line linux list lists loan loop maintain matching maze millimeter mouse mysqldb number numbers output parsing path port prime programming projects py2exe pygame pymailer python queue random rational raw_input recursion recursive scrolledtext searchingfile shebang singleton slicenotation split string strings table tails terminal text thread threading time tlapse tooltip tuple tutorial type ubuntu unicode url urllib urllib2 valueerror variable variables vigenere web wx.wizard wxpython xlwt






