void ltrim(char *s)// 去掉前部的
{
    int l=0,p=0,k=0;
    l = strlen(s);
    if( l == 0 ) return;
    p = 0;
    while( s[p] == ' ' || s[p] == '\t' )  p++;
    if( p == 0 ) return;
    while( s[k] != '\0') s[k++] = s[p++];
    return;
}
void rtrim(char *s)// 去掉尾部的
{
    int l=0,p=0;
    l = strlen(s);
    if( l == 0 ) return;
    p = l -1;
    while( s[p] == ' ' || s[p] == '\t' ) {
        s[p--] = '\0';
        if( p < 0 ) break;
    }
    return;
}

//使用
char a[] = "this is a dog.";
char *toks = " ";
char * tok = strtok( a, toks );
while( tok )
{
    if( tok == a )
        strcpy( a, tok );
    else
        tok = strtok( NULL, toks );
}
       
void strallcut(char *str)
{
    int i,j=0;
    char sp[512];
    for (i = 0; *(str + i) != '\0'; i++) {
        if (*(str + i) == ' ' )
            continue;
            sp[j++]=*(str + i);
        }
    sp[j] = 0;
    strcpy(str, sp);
}


blog comments powered by Disqus

Published

18 September 2013

Tags