数据转换 CString strtemp = _T("31")Messagebox(strtemp);怎样进行数据转换能使输出的值为31对应的ASCIi值 1 呢? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 char temp = atoi(strtemp.GetBuffer(0)); 输出用CString 。该怎么做呢? int iValue = atoi("31");char szMsg[2] = {0};sprintf(szMsg, "%c", (char)iValue);Messagebox(szMsg); CString = “313233”怎样能输出123呢 int Ascii2Char(const CString & sStr, CString &sOutput){ char *p = (LPCTSTR)sStr; char szTmp[3]; int iValue; char szMsg[2] = {0}; sOutput = ""; while(*p && *(p + 1)) { strncpy(szTmp, p, 2); iValue = atoi(szTmp); sprintf(szMsg, "%c", (char)iValue); sOutput += szMsg; p += 2; } return sOutput.GetLength();} 不能。31变成ASCII时变成13 CString strtemp = _T("313233"); CString strResult; int nasc = 0; for(int i=0; i<strtemp.GetLength(); i=i+2) { CString strMid = strtemp.Mid(i,2); swscanf(strMid,L"%02x",&nasc); strMid.Format(L"%c",nasc); strResult = strResult + strMid; } AfxMessageBox(strResult); CString Asc2Str(CString strSrc){ LPSTR *pszDest = new char[(strSrc.GetLength() + 3) / 2]; LPSTR *p = pszDest;#define _ASC2BIN(x) (((x) <= _T('9')) ? (x)-_T('0') : (((x) <= _T('F')) ? (x)-_T('A')+10 : (x)-_T('a')+10)) int i = 0; while(strSrc[i] != 0 && strSrc[i+1] != 0) { *p++ = (_ASC2BIN(strSrc[i]) << 4) + _ASC2BIN(strSrc[i+1]); i += 2; } *p = 0;#undef _ASC2BIN CString strDest = pszDest; delete [] pszDest; return strDest;} int Ascii2Char(CString& strIn, CString& strOut){ if(strIn.IsEmpty()) { AfxMessageBox(_T("Error!")); return -1; } strOut.Empty(); int len = strIn.GetLength(); int i=0; for(i=0; i<len; i++) { TCHAR ch = strIn.GetAt(i); if(ch < _T('0') || ch > _T('9')) { AfxMessageBox(_T("Error!")); return -1; } } CString strTmp(_T("")); for(i=0; i<len; i+=2) { strTmp = strIn.Mid(i, 2); strTmp.Format(_T("%c"), _tcstoul(strTmp, NULL, 16)); strOut += strTmp; } return 0;} 我重新写了一下:CString strtemp,strtemp1;char chartemp[200];for (int i=0;i<m_comdata.GetLength()/2;i++){ CString strMid =m_comdata.Mid(i*2);sscanf(strMid,"%02X",(chartemp+i));}帮忙看看这两者有什么区别吗? javascript能自动释放调用的activex中的对象 移动对话框中TOOLBAR的位置 关于语音聊天系统的几个问题 能回答了答案,愿散尽100分 如何获取主板的唯一ID(序列号)? 散个分,都得弄这么长的标题 很失望,再问一次,关于窗口风格而已. 关于截取某被遮挡窗口图像的问题?? 紧急:用odbc API编程怎么将内存中的图像数据保存到数据库中,最好一次处理多条记录。 ◆◆◆◆◆善良的石头请进◆◆◆◆◆ 关于组件ProgID的疑惑: 挂WH_CBT钩子 在win7下失效的原因 如何将CString保存为RTF格式的文件?
char szMsg[2] = {0};sprintf(szMsg, "%c", (char)iValue);
Messagebox(szMsg);
CString = “313233”
怎样能输出123呢
{
char *p = (LPCTSTR)sStr;
char szTmp[3];
int iValue;
char szMsg[2] = {0};
sOutput = "";
while(*p && *(p + 1))
{
strncpy(szTmp, p, 2);
iValue = atoi(szTmp);
sprintf(szMsg, "%c", (char)iValue);
sOutput += szMsg;
p += 2;
} return sOutput.GetLength();}
不能。
31变成ASCII时变成13
CString strtemp = _T("313233");
CString strResult;
int nasc = 0;
for(int i=0; i<strtemp.GetLength(); i=i+2)
{
CString strMid = strtemp.Mid(i,2);
swscanf(strMid,L"%02x",&nasc);
strMid.Format(L"%c",nasc);
strResult = strResult + strMid;
}
AfxMessageBox(strResult);
CString Asc2Str(CString strSrc)
{
LPSTR *pszDest = new char[(strSrc.GetLength() + 3) / 2];
LPSTR *p = pszDest;#define _ASC2BIN(x) (((x) <= _T('9')) ? (x)-_T('0') : (((x) <= _T('F')) ? (x)-_T('A')+10 : (x)-_T('a')+10))
int i = 0;
while(strSrc[i] != 0 && strSrc[i+1] != 0) {
*p++ = (_ASC2BIN(strSrc[i]) << 4) + _ASC2BIN(strSrc[i+1]);
i += 2;
}
*p = 0;
#undef _ASC2BIN CString strDest = pszDest;
delete [] pszDest;
return strDest;
}
int Ascii2Char(CString& strIn, CString& strOut)
{
if(strIn.IsEmpty())
{
AfxMessageBox(_T("Error!"));
return -1;
}
strOut.Empty();
int len = strIn.GetLength();
int i=0;
for(i=0; i<len; i++)
{
TCHAR ch = strIn.GetAt(i);
if(ch < _T('0') || ch > _T('9'))
{
AfxMessageBox(_T("Error!"));
return -1;
}
} CString strTmp(_T(""));
for(i=0; i<len; i+=2)
{
strTmp = strIn.Mid(i, 2);
strTmp.Format(_T("%c"), _tcstoul(strTmp, NULL, 16));
strOut += strTmp;
}
return 0;
}
char chartemp[200];
for (int i=0;i<m_comdata.GetLength()/2;i++)
{
CString strMid =m_comdata.Mid(i*2);
sscanf(strMid,"%02X",(chartemp+i));
}帮忙看看这两者有什么区别吗?