字符串中的子串替换为指定串
作者:互联网
char *strrpc(char *str,char *oldstr,char *newstr) { int i = 0; char bstr[strlen(str)];//转换缓冲区 memset(bstr,0,sizeof(bstr)); for(i = 0; i < strlen(str); i++) { if(!strncmp(str+i,oldstr,strlen(oldstr))) {//查找目标字符串 strcat(bstr,newstr); i += strlen(oldstr) - 1; }else { strncat(bstr,str + i,1);//保存一字节进缓冲区 } } strcpy(str,bstr); return str; }
dstName = strrpc(srcName, "/sdb/data/","/mnt/usb33/download/"); 将字符串srcName中的/sdb/data/替换成后者
标签:子串,oldstr,char,str,bstr,字符串,strlen,替换 来源: https://www.cnblogs.com/fangzheng-nie/p/13186019.html