• Tutorials
  • DSA
  • Data Science
  • Web Tech
  • Courses
August 13, 2024 |3.8K Views

Replace a character c1 with c2 and c2 with c1 in a string S

  Share   Like
Description
Discussion

Given a string S, c1 and c2. Replace character c1 with c2 and c2 with c1. Examples: Input : grrksfoegrrks, c1 = e, c2 = r Output : geeksforgeeks Input : ratul, c1 = t, c2 = h Output : rahul Replace a character c1 with c2 and c2 with c1 in a string S : https://www.geeksforgeeks.org/replace-character-c1-c2-c2-c1-string-s/Given a string S, c1 and c2. Replace character c1 with c2 and c2 with c1. 
Examples: 
 

Input : grrksfoegrrks,
       c1 = e, c2 = r 
Output : geeksforgeeks

Input : ratul,
       c1 = t, c2 = h 
Output : rahul


Replace a character c1 with c2 and c2 with c1 in a string S  : https://www.geeksforgeeks.org/replace-character-c1-c2-c2-c1-string-s/