• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
张纯睿
博客园    首页    新随笔    联系   管理    订阅  订阅

字符串的ASCII 读写

CString CMacroCmd::String2Ascii(CString strValue)
{
#ifdef UNICODE
CString strAscii = _T("");
for (int i=0; i<strValue.GetLength(); i++)
{
CString stemp;
stemp.Format(_T("%04X"), strValue.GetAt(i));

strAscii = strAscii+stemp;
}
return strAscii;
#else
ASSERT(FALSE); // 必须是UNICODE
return strValue;
#endif
}

CString CMacroCmd::Ascii2String(CString strAscii)
{
#ifdef UNICODE
CString strValue = _T("");

int tch1 = 0; //TCHAR tch1 = 0x0000; 原因参考 http://www.cnblogs.com/carl2380/archive/2011/06/21/2086011.html
for (int i=0; i<strAscii.GetLength()/4; i++)
{
CString stemp1 = strAscii.Mid(i*4, 4);

_stscanf_s(stemp1.GetBuffer(0),_T("%x"),&tch1);

CString stemp3;
stemp3.Format(_T("%c"), tch1);
strValue = strValue+stemp3;
}
return strValue;
#else
ASSERT(FALSE); // 必须是UNICODE
return strAscii;
#endif
}

posted @ 2011-12-30 11:40  张纯睿  阅读(283)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3