編碼格式(未完待續......)

1. /u->中文:
    將/u後面的16進制轉化成10進制,而後賦值給wchar_t/byte;
2. 中文->/u:
 
3. utf-8:
    utf-8 w/o BOM:沒有BOM頭
    utf-8:有3個字節的BOM頭,EFBBBF(utf-16頭:FFFE),屬於unicode編碼格式;
 1 // 判斷是否有BOM頭,若是有,則去掉BOW頭,而後保存。
 2  string strVal;
 3  string strPath = CStringHelper::Unicode2ACSII(CProcHelper::GetCurrentProcessPath());
 4  strPath += "\\test_utf8.txt";
 5  ifstream ifs(strPath.c_str(), ios::binary);
 6  if (ifs.is_open())
 7  {
 8    stringstream ss;
 9    ss << ifs.rdbuf();
10    strVal = ss.str();
11    ifs.close();
12 
13    // 判斷是否有頭
14    // BOM頭:EFBBBF
15    bool b = false;
16    if (0xEF == (byte)strVal.at(0) &&
17     0xBB == (byte)strVal.at(1) &&
18     0xBF == (byte)strVal.at(2))
19    {
20        b = true;
21    }
22  
23   // 去掉頭
24   strVal = strVal.substr(3, strVal.length() - 3);
25 
26   string strPath2 = CStringHelper::Unicode2ACSII(CProcHelper::GetCurrentProcessPath());
27   strPath2 += "\\test_utf8_bk.txt";
28   ofstream ofs(strPath2, ios::binary);
29   if (ofs.is_open())
30   {
31    ofs << strVal;
32    ofs.close();
33   }
34  }
相關文章
相關標籤/搜索