今天无聊的时候 写了一个小题目 删除子串

来源:互联网 发布:用友软件u8教程 编辑:程序博客网 时间:2024/04/29 18:51
#include<iostream>#include<string.h>using namespace std;int delete_sub_str(const char *strFather, const char *strSon, char *strResult){int istrNum = 0;int iFatherLen = strlen(strFather);int iSonLen = strlen(strSon);char *strTemp = new char[iSonLen+1];int iSonLenTemp = iSonLen;int iTemp =0 ;int iRcode =0;int iResult = 0;for(int i=0;i<iFatherLen;i++){if((i+iSonLen) > iFatherLen){strResult[iResult++] = strFather[i];}else   {while(( iSonLenTemp -- ) > 0){  strTemp[iTemp] = strFather[i + iTemp];  iTemp ++;}strTemp[iTemp] = '\0';   iTemp = 0;iSonLenTemp = iSonLen;int j =0;for(j =0;j < iSonLen; j++){ if(strSon[j] != strTemp[j]) {strResult[iResult++] = strFather[i];break; }}if(j == iSonLen){ i = i + iSonLen-1; istrNum++;}}}strResult[iResult] = '\0';delete[]strTemp; return istrNum;}int main(){char s[100];int num = delete_sub_str("123abc12de234fg1hi34j123k","123",s);//123abc12de234fg1hi34j123kstd::cout<<"NUM:"<<num<<"  "<<"Result:"<<s<<std::endl;getchar();return 0;}


0 0