void deletesub(string &str,const string &sub,int n)
{
int m,flag=0,num=0; //num是子串出现的次数
while(flag==0)
{
m=str.find(sub);//在str中找子串sub,返回起点下标
if(m<0)//没找到
flag=1;
else
{
str.erase(m,n);//删除子串,起点和sub长度
num++;
}
}
cout<<str<<endl;// 输出删除后的字符串
}
相关文章
- mongodbTemplate更新或删除子元素为数组的数据
- shell中取字符串子串的几种方式
- 【xlog日志文件】怎么删除里面包含某些字符串的行(使用excel)
- LeetCode 5. 最长回文子串(C++)
- leetCode 30.Substring with Concatenation of All Words (words中全部子串相连) 解题思路和方法
- [leetcode]30. Substring with Concatenation of All Words由所有单词连成的子串
- [LeetCode] 30. Substring with Concatenation of All Words 串联所有单词的子串
- 【练习】给定两个字符串str1和str2,输出两个字符串的最长公共子串 题目保证str1和str2的最长公共子串存在且唯一。
- 给定两个字符串str1和str2,返回两个字符串的最长公共子串 --js
- 后缀树(Suffix Trie)子串匹配结构