I have written down few string manipulation routines. First one can replace a word. Here is the code:
std::string string_replace(std::string src, const std::string fnd, const std::string rep, int time=-1) {
int count = 0;
std::string::size_type index = src.find(fnd);
while(index != std::string::npos && (count < time || time == -1) {
src.erase(index, fnd.size());
src.insert(index, rep);
index = src.find(fnd, index + rep.size());
count++;
}
return src;
}
Second routine is a string splitter:
std::vector
std::string::size_type pos = 0, index;
std::vector
std::string token;
index = str.find(deli);
while(index != std::string::npos) {
token = str.substr(pos, index - pos);
if(token.size())
result.push_back(token);
pos = index + deli.size();
index = str.find(deli, pos);
}
if(pos <>
result.push_back(str.substr(pos, str.size()));
}
return result;
}


