当前位置:   article > 正文

MFC字符串转换(UTF8、gb2312)_cstring转gb2312

cstring转gb2312
  1. #ifndef _ttol
  2. #define _ttol ToolBase::TToL
  3. #endif
  4. class ToolBase
  5. {
  6. public:
  7. static CString UTF8ToGB2312(const char *pSrc, int iLen)
  8. {
  9. char pResult[2048] = {0};
  10. int i = 0, j = 0;
  11. while (i < iLen)
  12. {
  13. if (pSrc[i] < 0 && i+2<iLen && pSrc[i+1] < 0 && pSrc[i+2] < 0)
  14. {
  15. WCHAR Wtemp = UTF8ToUnicode__(pSrc + i);
  16. char Ctemp[4] = {0};
  17. UnicodeToGB2312__(Ctemp, Wtemp);
  18. pResult[j] = Ctemp[0];
  19. pResult[j + 1] = Ctemp[1];
  20. i += 3;
  21. j += 2;
  22. }
  23. else
  24. {
  25. pResult[j++] = pSrc[i++];
  26. }
  27. }
  28. return CString(pResult);
  29. }
  30. static long TToL(const CString& data)
  31. {
  32. USES_CONVERSION;
  33. char* tmp = T2A(data);
  34. return atol(tmp);
  35. }
  36. private:
  37. static WCHAR UTF8ToUnicode__(const char pSrc[3])
  38. {
  39. WCHAR Wtemp;
  40. char* uchar = (char *)&Wtemp;
  41. uchar[1] = ((pSrc[0] & 0x0F) <<
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小小林熬夜学编程/article/detail/123094
推荐阅读
  

闽ICP备14008679号