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", "&");

  

posted @ 2018-06-07 15:19  那一剑的風情  阅读(327)  评论(0)    收藏  举报