- 去除字符串中所有空格
- voidVS_StrTrim(char*pStr)
- {
- char *pTmp = pStr;
-
- while (*pStr != '/0')
- {
- if (*pStr != ' ')
- {
- *pTmp++ = *pStr;
- }
- ++pStr;
- }
- *pTmp = '/0';
- }
-
- 去除字符串右边空格
- void VS_StrRTrim(char *pStr)
- {
- char *pTmp = pStr+strlen(pStr)-1;
-
- while (*pTmp == ' ')
- {
- *pTmp = '/0';
- pTmp--;
- }
- }
-
-
- 去除字符串左边空格
- void VS_StrLTrim(char *pStr)
- {
- char *pTmp = pStr;
-
- while (*pTmp == ' ')
- {
- pTmp++;
- }
- while(*pTmp != '/0')
- {
- *pStr = *pTmp;
- pStr++;
- pTmp++;
- }
- *pStr = '/0';
- }
然后用方法一我转了一个全是int 类型的DateTime类,代码很难看
- string DateTime::toString()
- {
- char temp1[100],temp2[20];
- sprintf(temp1, "%d", this->year);
- sprintf(temp2, "%d", this->month);
- strcat(temp1,temp2);
- sprintf(temp2, "%d", this->day);
- strcat(temp1,temp2);
- sprintf(temp2, "%d", this->hour);
- strcat(temp1,temp2);
- sprintf(temp2, "%d", this->minute);
- strcat(temp1,temp2);
- sprintf(temp2, "%d", this->second);
- strcat(temp1,temp2);
- sprintf(temp2, "%d", this->milliSecond);
- strcat(temp1,temp2);
- string str(temp1);
- return str;
- }