I mean, i want to replace str[9:11] for another string.
If I do str.replace(str[9:11], "###") It doesn't work, because the sequence [9:11] can be more than one time.
If str is "cdabcjkewabcef" i would get "cd###jkew###ef" but I only want to replace the second.
7
votes
Using 'string.replace' converts every occurrence of the given text to the text you input. You are not wanting to do this, you just want to replace the text based on its position (index), not based on its contents.
- Luke
6 Answers
14
votes
3
votes
2
votes
1
votes