Given a string S, c1 and c2. Replace character c1 with c2 and c2 with c1.
Input : grrksfoegrrks, c1 = e, c2 = r Output : geeksforgeeks Input : ratul, c1 = t, c2 = h Output : rahul
Traverse through the string and check for the occurrences of c1 and c2. If c1 is found then replace it with c2 and else if c2 is found replace it with c1.
Time Complexity: O(n)
Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: DSA Self Paced. Become industry ready at a student-friendly price.
- Replace every character of string by character whose ASCII value is K times more than it
- Replace every character of a string by a different character
- Modify the string such that every character gets replaced with the next character in the keyboard
- Find a string such that every character is lexicographically greater than its immediate next character
- Check if frequency of character in one string is a factor or multiple of frequency of same character in other string
- Map every character of one string to another such that all occurrences are mapped to the same character
- Lexicographically smallest string formed by appending a character from the first K characters of a given string
- Lexicographically smallest string formed by appending a character from first K characters of a string | Set 2
- Replace two substrings (of a string) with each other
- Replace all occurrences of pi with 3.14 in a given string
- Find the character in first string that is present at minimum index in second string
- Convert the string into palindrome string by changing only one character.
- Queries to find the last non-repeating character in the sub-string of a given string
- Queries to find the first non-repeating character in the sub-string of a string
- URLify a given string (Replace spaces is %20)
- Replace all occurrences of a string with space
- Replace all occurrences of string AB with C without using extra space
- Program to replace every space in a string with hyphen
- Replace every vowels with lexicographically next vowel in a String
- Replace all consonants with nearest vowels in a string
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.