int deleteSpaceEnterTab(char* srcstr) {
if (NULL == srcstr) {
printf("parameter error\n");
return -1;
}
/* 删除行尾的换行符 */
int tmpLen = strlen(srcstr);
while ('\r' == srcstr[tmpLen - 1] || '\n' == srcstr[tmpLen - 1]) {
srcstr[tmpLen - 1] = '\0';
--tmpLen;
}
/* 删除行尾的空格和tab*/
tmpLen = strlen(srcstr);
while (srcstr[tmpLen - 1] == ' ' || srcstr[tmpLen - 1] == '\t') {
srcstr[tmpLen - 1] = '\0';
--tmpLen;
}
/* 删除行首的空格和tab */
tmpLen = strlen(srcstr);
char* pstr = srcstr;
while (*srcstr == ' ' || *srcstr == '\t') {
++srcstr;
}
/* 判断是否需要字符前移 */
if (pstr == srcstr) {
return 0;
}
/* 字符前移 */
while ('\0' != *srcstr) {
*pstr++ = *srcstr++;
}
*pstr = '\0';
return 0;
}