#include "stdafx.h" //linux 底下要去掉这一行
#include <stdio.h>
#include<stdlib.h>
#include <string.h>
#include <malloc.h>
char matchStr1[]="111,aaa,ddd";
static char *strcpyNew(char *strDes, char *strSrc)
{
if(NULL==strSrc) return strDes;
strDes=(char *)malloc(strlen(strSrc)+1); //assign more 1 space to save'\0'
char *p=strDes;
while(*strSrc!='\0')
{
*p++=*strSrc++;
}
*p='\0';
return strDes;
}
static char * DelStr(char *sSrc, char *sMatchStr)
{ if(strcmp(sMatchStr,"")==0||(NULL==sSrc)||(sSrc==""))return sSrc;
char *seps =",";
char *token = strtok(sMatchStr, seps);
while(token)
{
char *FindPos = strstr(sSrc, token);
if(FindPos)
while(FindPos)
{
int i;
int newLen=strlen(sSrc);
int leftLen=FindPos - sSrc;
char *p=(char *)malloc(newLen);
for(i=0;i<leftLen;i++)
{
p[i]=sSrc[i];
}
for(i=leftLen;i<newLen;i++)
{
p[i]=sSrc[i+strlen(token)];
}
sSrc= strcpyNew(sSrc, p);
free(p);
FindPos = strstr(sSrc, token);
}
token = strtok(NULL, seps);
}
return sSrc;
}
int main(int argc, char* argv[])
{
char * abc="333 333 aaa aaa ddd 444 aaa 666";
printf("--原先--\n%s,size=%d\n",abc,strlen(abc)); abc=DelStr(abc,matchStr1);
printf("--现在--\n%s,size=%d\n",abc,strlen(abc));
return 0;
}
 

C 替换字符方法--1的更多相关文章

  1. C 替换字符方法

    // 444.cpp : Defines the entry point for the console application. // #include "stdafx.h" # ...

  2. JAVA中替换字符的方法replace和replaceAll 区别

    replace和replaceAll是JAVA中常用的替换字符的方法,它们的区别是:1)replace的参数是char和CharSequence,即可以支持字符的替换,也支持字符串的替换(CharSe ...

  3. php中按指定标识及长度替换字符的方法代码

    /** * 按指定标识及长度替换字符 * @param $str * @param int $start 开始的位数 * @param int $end 后面保留的位数 * @param string ...

  4. JS Replace() 全部替换字符的用法

    好久不写js了,今早遇到替换字符的,就浪费了点时间,由此,要记录下来.replace()方法:楼主有个字符串,需要替换掉其中的一些字母,如: var test='123helo123boy123hi' ...

  5. python字符串内容替换的方法(转载)

    python字符串内容替换的方法 时间:2016-03-10 06:30:46来源:网络 导读:python字符串内容替换的方法,包括单个字符替换,使用re正则匹配进行字符串模式查找与替换的方法.   ...

  6. JavaScript 字符串函数 之查找字符方法(一)

    1.JavaScript查找字符方法   首先看一张 有关字符串函数的查找字符的方法图 接下里补充里面的方法说明 2.charAt()     charAt() 方法返回字符串中指定位置的字符 语法 ...

  7. [转载]js正则表达式/replace替换变量方法

    原文地址:http://www.blogjava.net/pingpang/archive/2012/08/12/385342.html JavaScript正则实战(会根据最近写的不断更新) 1.j ...

  8. js正则表达式/replace替换变量方法

    转自:http://www.blogjava.net/pingpang/archive/2012/08/12/385342.html 1. javascript 正则对象替换创建和用法:/patter ...

  9. Linux下vi替换字符命令操作实例

    在Linux下的开发中,经常涉及到对文件里的字符进行处理,当中,对字符的替换操作也是非常的频繁. 本文以一个实际的文件为例,具体介绍了Linux下经常使用的vi替换字符命令,为相关的开发工作提供给了參 ...

随机推荐

  1. bootstrap实现弹出窗口

    bootstrap使用modal-dialog实现弹对话框. 一个对话框包含3部分: 对话框头部 modal-header 对话框内容体 modal-body 对话框底部 modal-footer 如 ...

  2. SNMP详解

    简单网络管理协议(SNMP)是TCP/IP协议簇的一个应用层协议.在1988年被制定,并被Internet体系结构委员会(IAB)采纳作为一个短期的网络管理解决方案:由于SNMP的简单性,在Inter ...

  3. tfw格式图解

    话不多说,直接看图. 上图中的UV坐标,实际上只的是图像的 横向坐标 和 纵向坐标 .即图像的行和列坐标. 对于图上任意一个像素点(col,row)这个坐标,换算其地理坐标就十分简单. GeoX = ...

  4. CookieStore之Cookie的获取与保存

    Set<Cookie> allCookies = driver.manage().getCookies(); try { CookieStore cookiestore = new Bas ...

  5. 5.2---小数的二进制表示(CC150)

    public static String printBin(double num) { StringBuffer str = new StringBuffer(); str.append('0'); ...

  6. Python类的特点 (2) :类属性与实例属性的关系

    测试代码: #encoding:utf-8 class Parent(object): x=1 #x是Parent类的属性(字段) ls=[1,2] #ls是一个列表,也是Parent类的属性(字段) ...

  7. 图形化的Git

    原文:http://gitbook.liuhui998.com/6_5.html Git有不少图形化界面工具用于读取和维护仓库. 捆绑的GUI Git自带了两个使用Tcl/Tk写成的GUI程序. Gi ...

  8. 《Head First Servlet JSP》容器工作原理(如tomcat)

  9. Delete a node from BST

    Given a root node reference of a BST and a key, delete the node with the given key in the BST. Retur ...

  10. Valid Number

    Validate if a given string is numeric. Some examples:"0" => true" 0.1 " => ...