Program to Replace a Substring in a String | FACE Prep
Published on 09 Mar 2020
Program to replace a substring in a string is discussed here. The steps for replacing a substring with another string are given below.
string to be replaced: hi
string to be replaced with: hey
output: hey hello
Algorithm to Replace a substring in a string
- Input the full string (s1).
- Input the substring from the full string (s2).
- Input the string to be replaced with the substring (s3).
- Find the substring from the full string and replace the new substring with the old substring (Find s2 from s1 and replace s1 by s3).
Program to Replace a substring in a string
Asked in recruitment drive of Wipro.
Enter the main String:Notwithstanding
Enter the string to be replaced:with
Enter the replacing string: under
If you have any feedback about this
article and want to improve this, please write to firstname.lastname@example.org