Sep 27, 2011 at 4:48pm Sep 27, 2011 at 4:48pm UTC
how would i go about replacing a character with another character.
an example would be replace all 'a' with 'b'.
imput: abc
output: bbc
i need to detect all 'a' in the string and replace with 'b' no matter the length or size of the string. string is only one word with no spaces.
Last edited on Sep 27, 2011 at 4:48pm Sep 27, 2011 at 4:48pm UTC
Sep 27, 2011 at 5:09pm Sep 27, 2011 at 5:09pm UTC
You can think of a string as "an array of characters". So just check each character of the string for whether it's the one you want to replace, and then... just do it.
Sep 28, 2011 at 4:24am Sep 28, 2011 at 4:24am UTC
Don't worry i finally figured it out.
replace( str.begin(), str.end(), 'a', 'b');