How to edit a string | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

How to edit a string

An example of this would be if I could always change the first letter of an inputted string to N or something

12th Feb 2020, 8:22 PM
Christian0972
2 Answers
+ 2
string s="would" ; s[0]='c'; s="could"; You mean like this?
12th Feb 2020, 8:33 PM
Jayakrishna 🇮🇳
0
String is an array of char, you can change letters using positions like: string str = "test"; str[0] = 'b'; cout << str; //Output --> best; str[2] = 'a'; cout << str; //Output --> beat; Or for edit a string by replacing more then one char, you can use member function replace(), See this example http://www.cplusplus.com/reference/string/string/replace/
12th Feb 2020, 9:48 PM
Rafik Abdelhak Nadir
Rafik Abdelhak Nadir - avatar