Chinaunix首页 | 论坛 | 博客
  • 博客访问: 158794
  • 博文数量: 25
  • 博客积分: 1222
  • 博客等级: 中尉
  • 技术积分: 322
  • 用 户 组: 普通用户
  • 注册时间: 2007-09-27 10:18
文章分类
文章存档

2011年(7)

2010年(9)

2009年(9)

我的朋友

分类: LINUX

2010-08-23 20:46:39

(1)从给定的字符串中删除特定字符串中出现的字符
//通用ASCII的范围是0~127
void setcurrentchar(int cIndex[],char *pch)
{
    size_t i;
    if(pch == NULL) return;
    for(i = 0;i    {
        cIndex[pch[i]] = 1;
    }
}

//从给定的字符串中删除特定字符串中出现的字符
void deleteCurrentchar(char *pSrc,char*pch)
{
    char *pFast,*pSlow;
    int cIndex[127]={0};
    if(pSrc==NULL || pch == NULL) return;

    setcurrentchar(cIndex,pch);

    for(pSlow=pFast=pSrc;*pFast != '\0';)
    {
        if(cIndex[(int)*pFast])//如果该字符需要删除
        {
            //printf(" %c ",*pFast);
            pFast++;
        }
        else
        {
            *pSlow++ = *pFast++;
        }
    }
    *pSlow='\0';
}
(2)解析一个字符串,对字符串中重复出现的字符,只在第一次出现时保留
void setcurrentchar(int cIndex[],char ch)
{
   cIndex[ch] = 1;
}
void deleteSecondOccur(char *pSrc)
{
    int cIndex[128]={0};
    char *pF,*pS;

    if(pSrc == NULL) return;

    for(pS=pF=pSrc;*pF != '\0';)
    {
        if(cIndex[*pF])
        {
            printf("again:%c\n",*pF);
            pF++;
        }
        else
        {
            setcurrentchar(cIndex,*pF);
            *pS++=*pF++;
        }
    }
    *pS='\0';
}
阅读(1470) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~