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;
    }


  • 相关阅读:
    IO
    mouseover,mouseout和mouseenter,mouseleave
    【译】addEventListener 第二个参数
    Git 常用命令
    我对Backbone中url属性的理解
    小失误引起大失败
    收集各大网站的登录页面
    随笔2
    随笔1
    创建数据库
  • 原文地址:https://www.cnblogs.com/ahuo/p/1210704.html
Copyright © 2011-2022 走看看