C++删除string中所有匹配子串

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/Kwansy/article/details/83064899
void deleteAllMark(string &s, const string &mark)
{
	size_t nSize = mark.size(); // 子串的长度
	while(1)
	{
		size_t pos = s.find(mark); // 找到子串的位置
		if(pos == string::npos) // 找不到
		{
			return;
		}
		s.erase(pos, nSize); // 删除子串
	}
}

猜你喜欢

转载自blog.csdn.net/Kwansy/article/details/83064899
今日推荐