zoukankan      html  css  js  c++  java
  • c++字符串等长替换函数

    // Replace.cpp : Defines the entry point for the console application.
    //

    #include 
    "stdafx.h"
    #include 
    <shlwapi.h>
    #pragma comment(lib,"shlwapi.lib")
    int StrReplaceI(char* src,char* oldstr,char* newstr)
    {

        
    if (!src)
        
    {
            
    return 1;
        }

        
    int oldlen=strlen(oldstr);
        
    int newlen=strlen(newstr);
        
    if (newlen>oldlen)
        
    {
            
    return 2;
        }

        
    char *pold=StrStrI(src,oldstr);
        
    if (!pold)
        
    {
            
    return 3;
        }

        memset(pold,
    ' ',oldlen);
        memcpy(pold,newstr,newlen);
        
    return 0;
    }

    int main(int argc, char* argv[])
    {
        printf(
    "Hello World!\n");
        
    char buf[]="1234 567 890";

        StrReplaceI(buf,
    "567","99");
        printf(
    "%s\n",buf);
        
        
    return 0;
    }


  • 相关阅读:
    设计模式总结
    centos7.5 安装python3.7
    搭建yum软件源
    centos安装gitbook
    编译技术
    samba安装
    docker命令
    shell基础知识
    随笔
    虚拟机字节码执行引擎(三)
  • 原文地址:https://www.cnblogs.com/ahuo/p/1210704.html
Copyright © 2011-2022 走看看