How to replace specific character within an array with another character from an array?

???
Last edited on
you cannot easily do it that way (direct manipulations) because numbers to words.
you can't replace "#" with "one" (one letter with 3, or three, etc) directly and simply. If it were just replacing with '1' or '2' it would work but '10' is trouble there as well.

there are string commands to do it for you, and you can do it yourself if that is the goal.
to do it yourself, you can find() the letter you want to change ('?' or '#') and use that to take substrings (substr()), chop it up and rebuild it with the replacement. There are more efficient ways but that is the direct/simple way.
to do it with string functions, there is a replace already.
Last edited on
@jonnin Could you give me an example? I'm having a hard time following.
string s = "blah blah # moo ? words";
size_t here = s.find("#");
s.replace(here, 1, "ELEVENSIES");
here = s.find("?");
s.replace(here, 1, "x");

if you want to do that without using the string functions, it is a lot more workaround and doing it efficiently is a little weird, using substring is simple but slower.
Last edited on
Topic archived. No new replies allowed.