Home » Java » java – C# replace third occurrence of a character with just a another character-Exceptionshub

java – C# replace third occurrence of a character with just a another character-Exceptionshub

Posted by: admin February 25, 2020 Leave a comment

Questions:

Let’s say I have this string, “Hello User P “, I would like to replace the “P” with just one “$”, so it should be “Hello User $”.

If its “Hello User P”, it should be “Hello User $”.

It should just replace only the third occurrence of a string or character not others.

Below is the sample input and output format:

Input: Hello User P
Output: Hello User $

How to&Answers: