//清空left空字符
static char * trim_left(char *buf)
{int len,i;
char * tmp = NULL;len = strlen(buf);
if(len==0) { return buf; } tmp = (char*)malloc(len); memset(tmp,0x00,len); for(i = 0;i < len;i++) { if (buf[i] !=' ') { break; } } if (i < len) { strncpy(tmp,(buf+i),(len-i)); /*i is the number of space in the left*/ } strncpy(buf,tmp,len); free(tmp); return buf;}
//清空right空字符
static char * trim_right(char *buf){ int len,i; char * tmp=NULL; len = strlen(buf); if(len==0) { return buf; } tmp = (char*)malloc(len); memset(tmp,0x00,len); for(i = 0;i < len;i++) { if (buf[len-i-1] !=' ') { break; } } if (i < len) { strncpy(tmp,buf,len-i); } strncpy(buf,tmp,len); free(tmp); return buf;}//清空空字符
static int getstr_trim(char *outstr, char *instr)
{ if ((NULL == outstr) || (NULL == instr)) { return NULL; } int i = 0; char *tmp = instr; while(*instr != ' ') { i++; instr++; } memcpy(outstr, tmp, i); return 0;}
//清空指定字符
static int getstr_trimchar(char *instr, char trim_char)
{ char tmp_str[50]; if (NULL == instr) { return D_FAILURE; } if (strlen(instr) > sizeof(tmp_str)) { return D_FAILURE; } int i = 0; char *tmp = tmp_str; strcpy(tmp_str,instr); while(*instr) { if(*tmp != trim_char) { *instr = *tmp; instr++; } tmp++; } *instr = '\0'; return D_SUCCESS;}