作者在 2010-07-02 20:14:55 发布以下内容
#include <stdio.h>
//#include <string.h>
#include <string>
char* source = "sdabcs";
int main()
{
std::string cc;
char dec[100]={0};
int i ;
char *pstr = source,*pstr1=source;
printf("%s\n",source);
for (i=0;i<(strlen(source)-2);i++)
{
printf("%d,%s\n",strncmp( pstr,"abc",3),pstr);
if(!strncmp( pstr,"abc",3))
{
strcat(dec,"zhong");
pstr += 2;
pstr1 = pstr1+4;
}
else
{
dec[(pstr1-source)]=*pstr;
dec[(pstr1-source)+1]=0;
}
pstr += 1;
pstr1 = pstr1 + 1;
}
printf("%s\n",dec);
return 0;
}
把字符串 中的子串 “abc” 使用"zhong" 进行替换//#include <string.h>
#include <string>
char* source = "sdabcs";
int main()
{
std::string cc;
char dec[100]={0};
int i ;
char *pstr = source,*pstr1=source;
printf("%s\n",source);
for (i=0;i<(strlen(source)-2);i++)
{
printf("%d,%s\n",strncmp( pstr,"abc",3),pstr);
if(!strncmp( pstr,"abc",3))
{
strcat(dec,"zhong");
pstr += 2;
pstr1 = pstr1+4;
}
else
{
dec[(pstr1-source)]=*pstr;
dec[(pstr1-source)+1]=0;
}
pstr += 1;
pstr1 = pstr1 + 1;
}
printf("%s\n",dec);
return 0;
}