-
c++字符串等长替换函数
// Replace.cpp : Defines the entry point for the console application.
//
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
#include "stdafx.h"
#include <shlwapi.h>
#pragma comment(lib,"shlwapi.lib")
int StrReplaceI(char* src,char* oldstr,char* newstr)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
{
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
if (!src)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
return 1;
}
int oldlen=strlen(oldstr);
int newlen=strlen(newstr);
if (newlen>oldlen)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
return 2;
}
char *pold=StrStrI(src,oldstr);
if (!pold)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
return 3;
}
memset(pold,' ',oldlen);
memcpy(pold,newstr,newlen);
return 0;
}
int main(int argc, char* argv[])
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
{
printf("Hello World!\n");
char buf[]="1234 567 890";
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
StrReplaceI(buf,"567","99");
printf("%s\n",buf);
return 0;
}
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
-
相关阅读:
python+soket实现UDP协议的客户/服务端中文聊天程序
如何实现PyQt5与QML响应彼此发送的信号?
用 eric6 与 PyQt5 实现python的极速GUI编程(系列04)---- PyQt5自带教程:地址簿(address book)
用 eric6 与 PyQt5 实现python的极速GUI编程(系列03)---- Drawing(绘图)(3)-- 画线
用 eric6 与 PyQt5 实现python的极速GUI编程(系列03)---- Drawing(绘图)(2)-- 画点
用 eric6 与 PyQt5 实现python的极速GUI编程(系列03)---- Drawing(绘图)(1)-- 绘写文字
仿百度壁纸client(六)——完结篇之Gallery画廊实现壁纸预览已经项目细节优化
软件概要设计说明书—模板
Android--Handler的用法:在子线程中更新界面
在PreferenceAcitity中使用Fragement时避免额外的Left和RightPadding
-
原文地址:https://www.cnblogs.com/ahuo/p/1210704.html
Copyright © 2020-2023
润新知