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


  • 相关阅读:
    SqlDataAdapter 类
    新博开
    gcc编译C++程序

    抖动
    css3 导航效果
    javascript判断IE浏览器的版本
    CSS样式表继承详解
    css选择器
    鼠标样式
  • 原文地址:https://www.cnblogs.com/ahuo/p/1210704.html
Copyright © 2011-2022 走看看