cplusplus
.com
TUTORIALS
REFERENCE
ARTICLES
FORUM
C++
Tutorials
Reference
Articles
Forum
Forum
Beginners
Windows Programming
UNIX/Linux Programming
General C++ Programming
Lounge
Jobs
Forum
Beginners
replacing a char with another char in a
replacing a char with another char in a string
Sep 27, 2011 at 4:48pm UTC
suede
(2)
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 UTC
Sep 27, 2011 at 5:09pm UTC
hanst99
(2869)
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 UTC
suede
(2)
Don't worry i finally figured it out.
replace( str.begin(), str.end(), 'a', 'b');
Topic archived. No new replies allowed.