typedef struct{
char data[MaxSize];
int len;
}SqString;
int Index(SqString S,SqString T,int pos)
{//查找子串
int i,j;
i=pos-1;j=0;
while(i
if(S.data[i]==T.data[j]){i++;j++;}
else
{i=i-j+1;j=0;}
if(j>=T.len)return i-j+1;
else return 0;
}
void Replace(SqString &S,SqString T,SqString R)
{
int i,j,pos=1;
SqString sub;
while(pos<=S.len-T.len){
i=Index(S,T,pos);
if(i)
{
sub.len=S.len-i-T.len+1;
//截取S中替换T串后面的子串并存入sub
for(j=0;j
//替换字符串
for(j=0;j
//将sub子串链接到后面
for(j=0;j
S.len=i+R.len+sub.len-1;
pos=i+R.len;
}
}
}