消除多余空格
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;
}