Created
December 13, 2013 02:40
-
-
Save adow/7939096 to your computer and use it in GitHub Desktop.
char* string trim
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 去掉前部的 | |
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