Created
May 9, 2011 15:07
-
-
Save froop/962699 to your computer and use it in GitHub Desktop.
[C言語] 文字列trim
This file contains hidden or 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
char *c_trim(char *cpStr) | |
{ | |
int i; | |
char *cpStart; /* 文字列の先頭位置 */ | |
/* 後ろのスペースを削除 */ | |
for (i = strlen(cpStr)-1; i >= 0; i--) | |
{ | |
if (cpStr[i] != ' ') | |
{ | |
break; | |
} | |
cpStr[i] = '\0'; | |
} | |
/* 前スペースを除いた先頭を探す */ | |
cpStart = cpStr; | |
while (*cpStart == ' ') | |
{ | |
cpStart++; | |
} | |
/* 前スペース分をシフト */ | |
memmove(cpStr, cpStart, strlen(cpStart) + 1); | |
return cpStr; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment