• <ruby id="5koa6"></ruby>
    <ruby id="5koa6"><option id="5koa6"><thead id="5koa6"></thead></option></ruby>

    <progress id="5koa6"></progress>

  • <strong id="5koa6"></strong>
  • 字符串處理

    發表于:2007-05-25來源:作者:點擊數: 標簽:幾個實用字符串處理
    幾個實用字符串處理函數 char *intercept(char *result_str, char const *former_str,int const begin_place_num,char const *begin_str, char const *end_str) /*功能:begin_place0時,取former_str中第begin_place個begin_str開始到end_str結束的字符串,b

    幾個實用字符串處理函數

    char *intercept(char *result_str, char const *former_str,int const begin_place_num,char const *begin_str, char const *end_str)
    /*功能:begin_place>0時,取former_str中第begin_place個begin_str開始到end_str結束的字符串,begin_place<0時, 取第begin_place個begin_str左邊的字符串,begin_place=0時取到空*/
    /*result_str=結果字符串,former_str=源字符串,begin_place_num=第幾個(開始字符串),begin_str=開始字符串,end_str結束字符串*/
    {
            char *l_current_place,*r_current_place,*swap_str;
            int i;

            if ( (begin_place_num==0) || ((l_current_place=strstr(former_str,begin_str)) == NULL) )  {
                    *result_str='';
                    return NULL;
            }

            for (i=2;i <= abs(begin_place_num);i++) {
                    swap_str = l_current_place;
                    if ( (l_current_place=strstr(swap_str+1,begin_str)) == NULL ) {
                            *result_str='';
                            return NULL;
                    }
            }

            if (l_current_place == NULL) {
                    *result_str='';
                    return NULL;
            }

            if( begin_place_num>0 ) {
                    r_current_place=strstr(l_current_place+strlen(begin_str),end_str);
                    l_current_place=l_current_place+strlen(begin_str);
                    if( strlen(begin_str)!=0 && strlen(end_str)!=0 )
                            if (l_current_place == r_current_place) {
                                    *result_str++='';
                                    return NULL;
                            }
                    while ((*result_str++ = *l_current_place++) != 0)
                            if (l_current_place == r_current_place) {
                                    *result_str++='';
                                    break;
                            }
            }
            else {
                    while( (*result_str++ = *former_str++) != 0)
                            if ( former_str == l_current_place ){
                                    *result_str++ = '';
                                    break;
                            }
            }
            return result_str;
    }

    char * r_intercept(char *result_str, char const *former_str,int const begin_place_num,char const *begin_str)
    /*功能:begin_place>0時,取former_str中倒數第begin_place個begin_str開始到結束的字符串,begin_place<0時, 取倒數第begin_place個begin_str左邊的字符串,begin_place=0時取到空*/
    /*result_str=結果字符串,former_str=源字符串,begin_place_num=第幾個(開始字符串),begin_str=開始字符串*/
    {

            char *current_place,*swap_str;
            int i,repeat_left,total=0;
            if ( (begin_place_num==0) || ((current_place=strstr(former_str,begin_str)) == NULL) ) {
                    *result_str = '';
                    return NULL;
            }
            while (current_place != NULL) {
                    swap_str=current_place;
                    current_place = strstr(swap_str+1,begin_str);
                    total++;
            }
            if ( (repeat_left=total-abs(begin_place_num)+1 ) <= 0 ) {
                    *result_str = '';
                    return NULL;
            }

            if ( (current_place=strstr(former_str,begin_str)) == NULL) {
                    result_str = '';
                    return NULL;
            }
            for (i=2;i <= repeat_left;i++) {
                    swap_str=current_place;
                    if ( (current_place=strstr(swap_str+1,begin_str)) == NULL) {
                            *result_str='';
                            return NULL;
                    }
            }

            if (begin_place_num > 0) {
                    current_place=current_place+strlen(begin_str);
                    while ((*result_str++ = *current_place++) != 0)
                            ;
            }
            else
            {
                    while ((*result_str++ = *former_str++) != 0)
                    {
                            if (former_str == current_place)
                            {
                                    *result_str++ = '';
                                    break;
                            }
                    }
            }
            return result_str;
    }

    char *clear_blank(char  *string)
    /*清除字符串兩端的空格,回車等*/
    {
            char *strl,*strr;
            for(strl=string;((*strl==' ')||(*strl == '\t')||(*strl == '\n')||(*strl == '\r') );*strl++);
            strr=string+strlen(string)-1;
            for(;(strr>=string) && ((*strr == ' ')||(*strr == '\n')||(*strr == '\r')||(*strr == '\t') );strr--);
            for(;strl<=strr;string++,strl++)
                    *string=*strl;
            *string++='';
            return string;
    }

    int ifloatcheck(char *string)
    /*判斷字符串是不是實數,0=是,1=否*/
    {
            char strnum[50];
            char *strl,*strr,*str;
            int i=0;
            double numstr;
            str=string;

            for(strl=string;((*strl==' ')||(*strl == '\t')||(*strl == '\n')||(*strl == '\r') );*strl++);
            strr=string+strlen(string)-1;
            for(;(strr>=string) && ((*strr == ' ')||(*strr == '\n')||(*strr == '\r')||(*strr == '\t') );strr--);
            for(;strl<=strr;string++,strl++)
                    *string=*strl;
            *string++='';
            string=str;

            while(*string!='')
            {
                    if(!isdigit(*string)&&*string!='.'&&*string!='+'&&*string!='-'&&*string!=' ')
                            return 1;
                    *string++;
            }
            string=str;

            if(strcmp(string,"+")==0)
                    i=1;
            numstr=atof(string);
            sprintf(strnum,"+%lf",numstr);
            if(strstr(strnum,string)==NULL)
                    i=1;
            return i;
    }

    原文轉自:http://www.kjueaiud.com

    評論列表(網友評論僅供網友表達個人看法,并不表明本站同意其觀點或證實其描述)
    老湿亚洲永久精品ww47香蕉图片_日韩欧美中文字幕北美法律_国产AV永久无码天堂影院_久久婷婷综合色丁香五月

  • <ruby id="5koa6"></ruby>
    <ruby id="5koa6"><option id="5koa6"><thead id="5koa6"></thead></option></ruby>

    <progress id="5koa6"></progress>

  • <strong id="5koa6"></strong>