WEB开发网
开发学院手机开发Windows Mobile 开发 Windows mobile 开发 找到并替换字符串 阅读

Windows mobile 开发 找到并替换字符串

 2010-03-26 21:30:00 来源:WEB开发网   
核心提示://找到并替换字符串#include #include #include using namespace std;char* replace(char *str,char *sub1,char *sub2,char *output);int main(int argc,char *argv[]){char str[50

//找到并替换字符串

#include

#include

#include

using namespace std;

char* replace(char *str,char *sub1,char *sub2,char *output);

int main(int argc,char *argv[])

{

char str[50] = "";

char sub1[50] = "";

char sub2[50] = "";

char output[100] = "";

cout<<"str";

cin>>str;

cout<<"sub1";

cin>>sub1;

cout<<"sub2";

cin>>sub2;

cout<< p>

getch();

return 0;

}

char* replace(char *str,char *sub1,char *sub2,char *output)

{

char *pOutput = output;

char *pStr = str;

int lenSub1 = strlen(sub1);

int lenSub2 = strlen(sub2);

while(*pStr)

{

pStr = strstr(str,sub1);

if (NULL != pStr)

{

memcpy(pOutput,pStr,pStr-str);

pOutput+=pStr-str;

memcpy(pOutput,sub2,lenSub2);

pOutput+=lenSub2;

pStr+=lenSub1;

str=pStr;

}

else

{

break;

}

}

*pOutput = '';

if (*str != '')

{

strcpy(pOutput,str);

}

return output;

{

}

}

Tags:Windows mobile 开发

编辑录入:coldstar [复制链接] [打 印]
赞助商链接