MFC字符编码规则

	int sizeTchar = sizeof(TCHAR);	//uncode=2, 多字节=1
	std::string str1 = "张三zhangsan";
	//{ 0xe5, 0xbc, 0xa0, 0xe4, 0xb8, 0x89, 0x7a, 0x68, 0x61, 0x6e, 0x67, 0x73, 0x61, 0x6e }; --> utf-8编码
	// //用notepad16进制查看,utf8 no bom和utf8 bom都是这个编码,只是bom时,文件头多了3个字节。
	// str1的值,从调试内存来看,当utf8-no bom & 多字节编码 时,同上
	// str1的值,从调试内存来看,当utf8-no bom & Unicode编码 时,同上
	// 
	// 
	// { d5 c5 c8 fd 7a 68 61 6e 67 73 61 6e }
	// str1的值,从调试内存来看,当utf8-bom & 多字节编码 时, -->GBK编码
	// str1的值,从调试内存来看,当utf8-bom & Unicode编码 时 { d5 c5 c8 fd 7a 68 61 6e 67 73 61 6e }
	// 

	CString strName1;
	GetDlgItem(IDC_STATIC)->GetWindowText(strName1);

	//{ d5 c5 c8 fd 7a 68 61 6e 67 73 61 6e }	//多字节字符集-从控件取得 --> GBK编码(与操作系统有关)
	//{ 5f20 4e09 007a 0068 0061 006e 0067 0073 0061 006e }	//unicode字符集-从控件取得--> UTF-16BE编码

	unsigned short buf1[128] = { 0 };
	int len = strName1.GetLength();
	for (int i = 0; i < len; i++)
	{
		TRACE("%04x \n", (unsigned short)strName1[i]);
	}

	TRACE("\n");

	//字符编码查询:
	//https://www.qqxiuzi.cn/bianma/zifuji.php

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值