Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Looking to do multiple search and replaces

Status
Not open for further replies.

fpemberton

Technical User
Aug 11, 2006
1
0
0
US
I have a string which is over 400 characters long and theres a "?" and a newline after every 100 characters. I was wondering how can I replace multiple substrings( 100 chars long) multiple times within a string. To put it another way, this is what i want to do.

string to find ("abcdef") replace it with ("ffffff")
search again, string to find ("decfef") replace it with ("gggggg"). Thanks, any help would be appreciated.
 
how about
Code:
replace_strings = {'abcdef': 'ffffff', 'decfef': 'gggggg'}

for key in replace_strings:
  data_string.replace(key, replace_strings[key])

-jeff
lost: one sig, last seen here.
 
import string
old_str = '''
One
Two
One
Two
One
Two
One
Two
One
Two
One
Two
'''
print "Old String",old_str
print "\n\n"
new_string = string.replace(old_str,'One','1')
print "New String",new_string
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top