欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

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");

}

结果:
C++基础-两头堵挖字符串

相关标签: C/C++基础