Home:ALL Converter>replace a character in a string using at function?

replace a character in a string using at function?

Ask Time:2012-08-14T16:43:33         Author:Swapp Sawant

Json Formatter

I have a string CorrAns = "Text", I want to replace a character at a particular position with a character from another string. I used the following:

CorrAns.replace(1,1,OtherString.at(pos));

But its giving error, what is the best way to do this??

Author:Swapp Sawant,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/11948730/replace-a-character-in-a-string-using-at-function
ecatmur :

replace has no overload taking size, size, char. You want\n\nCorrAns.replace(1, 1, 1, OtherString.at(pos));\n\n\nor\n\nCorrAns.replace(1, 1, OtherString.substr(pos, 1));\n",
2012-08-14T08:50:04
James Kanze :

Just use at (or the [] operator) accross the board:\n\ncorrAns[1] = otherString[pos];\n\n\n(Note that at rarely has the semantics you want. If a bounds error is\na precondition failure, as is usually the case, the last thing you want\nis an exception.) ",
2012-08-14T08:49:01
Naidu Ypvs :

Your syntax is wrong. There are several methods for replace() function. Check below :\n\nhttp://www.ansatt.hig.no/frodeh/ooprog/string2.html",
2012-08-14T08:49:25
yy