V++ MFC CEdit输出数组 UNICODE TO ASCII码

MFC怎么在静态编辑框中输出数组

//字符转ASCII码
void CUTF8Dlg::OnBnClickedButtonCharAscii()
{
 // TODO: 在此添加控件通知处理程序代码
 UpdateData(TRUE);
 int length = 0;
 CStringW sAscii;
 char* pAscii;
 char aa[1024];
 GetDlgItem(IDC_EDIT_CHINA)->GetWindowText(sAscii);
 pAscii = ConvertUnicode2Ascii(sAscii);  //调用Unicode转ASCII函数

 while (TRUE)
 {
  if (*pAscii == 0)
  {
   break;
  }
  else
  {
   aa[length] = *pAscii;
   length++;
  }
  pAscii++;
 }
 CString bb[1024];
 for (int j = 0; j< length; j++)
 {
  bb[j].Format(_T("%x "),aa[j]);  /把十六进制数组添加到字符串 

  byUTF8 += bb[j];
 }
 UpdateData(FALSE);  //显示输出结果
}

//UNICODE TO ASCII
char* CUTF8Dlg::ConvertUnicode2Ascii(CStringW &instr)
{
 wchar_t * wstr = instr.GetBuffer();
 int ulen = ::WideCharToMultiByte(CP_ACP, 0, wstr, -1, NULL, 0, NULL, NULL);
 char* date = new char[ulen+1];
 memset(date,0,sizeof(char)*(ulen+1));//格式化字符串
 WideCharToMultiByte(CP_ACP, 0, wstr, -1, date, ulen, NULL, NULL);
 date[ulen+1] = '';//最后一字解设置结束符
 return date;
}

原文地址:https://www.cnblogs.com/ransn/p/8035487.html