The elegant way to replace specific characters in Python -


i have strings unpredictable in terms of character content, know every string contains 1 character '*'.

how replace 2 characters after '*' non hard-coded string. non hard-coded string calculated checksum , converted string:

checksum_str = str(hex(csum).lstrip('0x')) 

you want like:

star_pos = my_string.find('*') my_string = my_string[:star_pos] + '*' + checksum_str + my_string[star_pos + 3:] 

Comments

Popular posts from this blog

Unable to remove the www from url on https using .htaccess -