Click to See Complete Forum and Search --> : making convertion of characters to ascii , Hex , Decimal


stephenwhite
October 29th, 1999, 04:52 AM
i have designed a dialog window in Visual C++ MFC
and i want to change my characters in my edit box IDC_CHARACTER m_strChar into ASCII then HEX and then Decimal has anyone got ideas how to do this and some help with the code would be great.
as i seemed to have hit a real wall.
many thanks
S

Younker
October 29th, 1999, 05:32 AM
You can use the function like this and you can change it to realize the convertion of the HEX and the Decimal.
CString CConvertDlg::ConvertToAscii(CString s)
{
CString sTemp;
char ch;
CString sTmp;
for (int i=0;i<s.GetLength();i++)
{
ch=s.GetAt(i);
sTmp=sTemp;
sTemp.Format("%s%d",sTmp,int(ch));
}
return sTemp;
}
then you can invoke this function like this
void CConvertDlg::OnConvertBtn()
{
CEdit * pEdit=(CEdit*)GetDlgItem(IDC_CHARACTER);
CString sText;
pEdit->GetWindowText(sText);
sText=ConvertToAscii(sText);
pEdit->SetWindowText(sText);
return;
}
Good luck