Skip to content

Instantly share code, notes, and snippets.

@adow
Created December 13, 2013 02:40
Show Gist options
  • Save adow/7939096 to your computer and use it in GitHub Desktop.
Save adow/7939096 to your computer and use it in GitHub Desktop.
char* string trim
// 去掉前部的
void ltrim(char *s)
{
long 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)
{
long 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;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment