string 字符串替换
void StringReplace(string &str, string srcSubStr, string decSubStr)
{
int iPos = 0;
while (str.find(srcSubStr, iPos) != string::npos)
{
iPos = str.find(srcSubStr, iPos);
str = str.replace(iPos, strlen(srcSubStr.c_str()), decSubStr);
iPos += strlen(srcSubStr.c_str());
}
}
//例子,将 字符串中 and 替换成 &
string sQueryValue = "f1 = 1 and f2 = 1";
StringReplace(sQueryValue, "and", "&");

浙公网安备 33010602011771号