c++ 实现字符串中替换字符串,也可去掉字符串中特定字符串

int string_replase(string &s1, const string &s2, const string &s3)
{
	string::size_type pos = 0;
	string::size_type a = s2.size();
	string::size_type b = s3.size();
	while ((pos = s1.find(s2,pos)) != string::npos)
	{
		s1.replace(pos, a, s3);
		pos += b;
	}
	return 0;
}
string s2 = "###ip##";
string s1 = "http://123###ip##678.com";
string s3 = "192";	
string_replase(s1, s2, s3);

猜你喜欢

转载自blog.csdn.net/avaado/article/details/81128098
今日推荐