我是靠谱客的博主 羞涩雪糕,这篇文章主要介绍C++ 字符串 处理 消除多余空格,现在分享给大家,希望可以做个参考。

消除多余空格
void CStringTestDlg::OnBnClickedOk()
{
CString str("i am    a  stu aa aa   ddd  s");
CString rlt = RemoveExtraSpace(str);
AfxMessageBox(rlt);
// TODO: Add your control notification handler code here
//OnOK();
}


CString CStringTestDlg::RemoveExtraSpace(CString str){
CString ret;
int i = 0;
bool lastChrIsSpace = false;
for(i = 0;i < str.GetLength() ;i ++){


if(str[i] == ' '){
if(lastChrIsSpace){
continue;
}
else{
ret.AppendChar(' ');
lastChrIsSpace = true;
}
}
else{
ret.AppendChar(str.GetAt(i));
lastChrIsSpace = false;
}
}
return ret;
}


最后

以上就是羞涩雪糕最近收集整理的关于C++ 字符串 处理 消除多余空格的全部内容,更多相关C++内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(58)

评论列表共有 0 条评论

立即
投稿
返回
顶部