利用C的strstr函数查找字符串,然后strcpy拷贝覆盖它。
#include
int main() {
char s1[] = "This string is used for testing strstr() function";
char s2[] = "used for";
char *s3;
s3 = strstr(s1, s2);
int p1 = s3-s1;
strcpy(s1+p1, s3+strlen(s2));
cout << s1 << endl;
return 0;
}
//这里只删除了一处匹配的字符串,如果有多处匹配,则循环处理。