A
ataru
I want to find the position of a character in a string and replace it another
if it is actually there, and I'd like the operation to be efficient. I'm
assuming the "standard" way to do this is something like
string s = "blah";
int i = s.find_first_of('a'); /* returns 2, I presume? */
s.replace(i,0,"e");
Right? Is this the best way (assuming I haven't made some stupid error)? Is
there a way to (easily!) get a character pointer from a C++ string so I can
just change that one character, like maybe
char *cp;
if( (cp=strchr(s.c_str(), 'a') != NULL)
*cp='e';
? If neither way is good, what's a better way?
(if this is a FAQ, I didn't see it...)
if it is actually there, and I'd like the operation to be efficient. I'm
assuming the "standard" way to do this is something like
string s = "blah";
int i = s.find_first_of('a'); /* returns 2, I presume? */
s.replace(i,0,"e");
Right? Is this the best way (assuming I haven't made some stupid error)? Is
there a way to (easily!) get a character pointer from a C++ string so I can
just change that one character, like maybe
char *cp;
if( (cp=strchr(s.c_str(), 'a') != NULL)
*cp='e';
? If neither way is good, what's a better way?
(if this is a FAQ, I didn't see it...)