C++基础-两头堵挖字符串
程序员文章站
2022-07-14 18:34:01
...
两头堵挖字符串
void TrimLeft_RightSpace(char *m_inBuf, char *m_outbuf)
{
int i = 0;
int j = strlen(m_inBuf)-1;
while (m_inBuf[i++] == ' ' && m_inBuf !='\0')
{}
while (m_inBuf[j--] == ' ' && m_inBuf != '\0')
{}
int ncount = j - i + 1;
memcpy(m_outbuf, m_inBuf+i,ncount);
m_outbuf[ncount] = '\0';
}
void main()
{
int count = 0;
char *p = " asderfghjlerjjiujer12 ";
char buf[24] = { 0 };
TrimLeft_RightSpace(p, buf);
cout << "原来:|" << p << "|"<<endl;
cout << "去掉前后空格:|" << buf <<"|"<< endl;
system("pause");
}
结果: