-5

Suppose a string is provided:

str = 'Abcdeaghag'

How to replace the second occurrence of 'a' in str?

Håken Lid
  • 22,318
  • 9
  • 52
  • 67
  • Have you made any attempt yourself? What happened? – roganjosh Oct 30 '17 at 19:44
  • Yes I tried with str.find() and str.replace() but it's replacing all the occurrences. But, I want to replace only the second occurrence? I am a newbie. So please help – Asish Saha Oct 30 '17 at 19:47
  • 1
    It's a pity that you didn't include your attempts in the question. Currently it looks like you just want someone to write the code for you which is why the question is being poorly received. Please see [How to ask](https://stackoverflow.com/help/how-to-ask) and be sure to include your attempts. – roganjosh Oct 30 '17 at 19:50

1 Answers1

0

Here's a hint, I recommend declaring an counter and initializing it to 0. Then each time you find an 'a' in the string, you increment the counter.