Set a character in a string at a given position. If the string is shorter - return -1

The countdown starts from 0, i.e. the first character has position 0.


Call:

int strposcharset(string sourcestr, int ipos, char chartoplace, string &strresult);



Here:

sourcestr - source string;

ipos - position to replace;

chartoplace - the character to replace with.

strresult - string result.


Example:

Read from position 2 the character in the string "ABCDE" and write the character '_' to position 4 of this string.


charch;
string st, strresult;
st = "ABCDEF";
int iret = strposcharget(st, 2, ch);
coutvar << ch ;
ch = 'W';
iret = strposcharset(st, 1, ch, strresult);
coutvar<<strresult;



As a result, the message window will display:


B

ABCD_F