首先mfc下字串只有兩種資料:char(乙個位元組)和wchar_t(兩個位元組),很多其他資料型別如tchar,wchar等都是這個兩個基本型別的巨集定義,byte是uchar
1、對話方塊列印char*
char* info="";
::messageboxa(this->m_hwnd, info, "", mb_ok);
2、cstring轉char*
int nlen;
char * wsabuf = null;
uses_conversion;
wsabuf = w2a(send_txt_str);//send_txt_str為cstring訊息
3、char*轉cstring
直接強制轉換
4、_t("aa")轉0xaa
byte byte1 = wcstol(_t("aa"), null, 16);
5、_t("你好")轉c4 e3 ba c3
用2的方法轉char*->byte*,定義乙個迴圈,在迴圈中定義乙個臨時cstring變數format取出單個byte元素
6、字串轉整數,「ff」、_t("ff")轉256
用atoi那一系列函式(a代表ascii,to代表轉化,i代表int)
同上還有itoa一系列函式
ttoi(),cstring轉整數
使用strtol系列函式:(str to long)
int a;
cstring str;
str=_("1234");
a=wcstol(str,null,10);
a->1234
7、_t("01ff")轉十進位制:511
long a = wcstol(_t("01ff"),null,16);//a=511
8、整數轉字串
_ltoa
9、把整數的十六進製制轉化成cstring
int a=20;
cstring temp_str;
temp_str.format(_t("%02x"),20);
10、c4 e3 ba c3轉_t("你好")
強制轉換(cstring)
使用strtol系列函式:(str to long)
int a;
cstring str;
str=_("1234");
a=wcstol(str,null,10);
a->1234
9、把整數的十六進製制轉化成cstring
Unicode和UTF 8之間的轉換
unicode是乙個字符集,而utf 8是unicode的其中一種,unicode是定長的都為雙位元組,而utf 8是可變的,對於漢字來說unicode占有的位元組比utf 8占用的位元組少1個位元組。unicode為雙位元組,而utf 8中漢字佔三個位元組。utf 8編碼字元理論上可以最多到6個位...
unicode和utf 8之間的轉換
最近在用vc 開發乙個小工具,平時用慣了.net,用起vc 最鬱悶的就是字串處理。當然最最讓人難於琢磨的就是字符集,編碼之間的轉換。通過這幾天的研究,終於明白了unicode和utf 8之間編碼的區別。unicode是乙個字符集,而utf 8是unicode的其中一種,unicode是定長的都為雙位...
中日文和UNICODE之間編碼的轉換
一 gbk unicode unsigned short gbk2uni unsigned short usgbk unsigned short usuni multibytetowidechar 936,0,lpcstr szeuc,2,usuni,1 return usuni unsigned ...