str.replace(pos, token.length(), value);
string replaceval; endpos = startpos+searchtoken.length();  if (str[endpos] == '%') { replaceval = value; } else {  int len = atoi(str.c_str()+endpos); if (len > value.length()) { len = value.length(); }   replaceval = value.substr(0, len);   while (str[endpos] != '%' && (endpos < str.length())) { endpos++; } }  str.replace(startpos, endpos-startpos+1, replaceval);
static void replaceAll(string & str,                       const string & token,                       const string & value){  int pos;  while ((pos = str.find(token)) != str.npos)  {    str.replace(pos, token.length(), value);  }}