[C++] 纯文本查看 复制代码
#include <stdio.h>
#include <string.h>
int main()
{
char str[] = "abcdefsimokaeikjfasim1ekdicakdlasimldaisim1eeazkadslsimlaisime1azsdfa";
char *p;
char *p1;
int i = 0;
int len = strlen(str);
int tmplen;
char tmp[len + 1];
char tmp2[len + 1];
memset(tmp, '\0', len+1);
memset(tmp2, '\0', len+1);
strcpy(tmp2, str);
while ((p1 = strstr(tmp2, "sim1"))) {
p = tmp2;
while (p != (p1 + 3)) {
tmp = *p;
p++;
i++;
}
p1 += 4;
tmplen = strlen(p1);
memmove(tmp2, p1, tmplen);
p1 = tmp2;
p1 += tmplen;
memset(p1, '\0', len+1-tmplen);
}
p = tmp;
p += i;
strcat(p, tmp2);
printf ("%s\n", str);
printf ("%s\n", tmp);
return 0;
}