#include<iostream>
#include<string>
using namespace std;
int delete_sub_str(char *input,char *sub_str,char *result)
{
int count=0;
int len = strlen(sub_str);
char *p = result;
while(*input != '\0'){
int i=0;
for(;i<len;i++)
{
*p = *input;
p++;
input++;
if(*input != *(sub_str+i))
break;;
}
if(i == len)
{
p = p-len;
count++;
}
}
*p='\0';
return count;
}
void main()
{
char* str="homehaveto filehavdreamideatoplanfast";
char* s="have";
char *res=(char*)malloc(sizeof(char)*100);
delete_sub_str(str,s,res);
cout<<res<<endl;
}
去除字符串中的重复子字符串
最新推荐文章于 2022-10-22 10:59:47 发布
本文提供了一个使用C++实现的示例程序,该程序演示了如何从一个字符串中删除所有指定子串出现的位置。通过遍历源字符串并与目标子串进行比较,找到匹配项并从结果字符串中排除。
1万+

被折叠的 条评论
为什么被折叠?



