This is the version I use on Linux:
char* trim(char *s) { char *pRun = s; while(*pRun == ' ') ++pRun; if(pRun != s) memmove(s, pRun, (strlen(pRun) + 1) * sizeof(char)); pRun = s + strlen(s) - 1; while(*pRun == ' ') --pRun; *(++pRun) = 0; return s; }And this is the version I use on Win32, which is Unicode-ready:
LPTSTR trim(LPTSTR s) { TCHAR *pRun = s; while(*pRun == TEXT(' ')) ++pRun; if(pRun != s) memmove(s, pRun, (lstrlen(pRun) + 1) * sizeof(TCHAR)); pRun = s + lstrlen(s) - 1; while(*pRun == TEXT(' ')) --pRun; *(++pRun) = 0; return s; }
No comments:
Post a Comment