PDA

View Full Version : string parsing in python



paulfox
April 20th, 2005, 11:56 PM
Hi all,
i'm wondering whats the best way for parsing a long string of text.
say i have a sentance like:
"hello my name is paul : )"
I'd want it to be scanned and then every occurance of "hello" is replaced with "howdy", and ": )" is replaced with "(SMILE)"

are there any easy ways of doing this in python?

thanks a lot for reading!

jdonnell
April 21st, 2005, 12:50 AM
http://docs.python.org/lib/string-methods.html



>>> str = "hello my name is paul : )"
>>> str.replace('hello', 'howdy')
'howdy my name is paul : )'
>>>