您当前的位置:首页 > 养生 > 内容

unicode转换(unicode编码如何转换成汉字)

本文目录

  • unicode编码如何转换成汉字
  • unicode如何转换成ANSI
  • 怎么将汉字转换成unicode
  • Swift 怎么把unicode编码转成中文
  • 如何将字符unicode码转换为实际字符

unicode编码如何转换成汉字

unicode编码不需要转换成汉字,因为unicode就是和字符关联的终极编码。windows中只有unicode码可以和字符直接关联,也就是使用国际标准的unicode字符集。中文windowsXp默认的内码是gbk(装过gb18030补丁的话也就变成gb18030),日文系统就是JIS,不同语言版本的windows都有不同的默认内码,这是每个国家的标准化管理局规定的。然后就是页码表的概念,所谓页码表就是把一个用系统默认编码(比如gbk,gb2312)表示的字符映射到对应unicode编码,而每个unicode编码对应着唯一确定的字符。这样就完成了地域性编码到国际标准码再到字符的对应关系。在控制面板-》区域和语言选择-》高级,里面可以看到window提供的所有页码表。绝非转载,无参考内容,均为个人理解参悟内容。

unicode如何转换成ANSI

Win32 提供 MultiByteToWideChar 和 WideCharToMultiByte 将为 Unicode 的 ANSI 字符串和 Unicode 字符串转换为 ANSI。代码如下:

/* * AnsiToUnicode converts the ANSI string pszA to a Unicode string * and returns the Unicode string through ppszW. Space for the * the converted string is allocated by AnsiToUnicode. */ HRESULT __fastcall AnsiToUnicode(LPCSTR pszA, LPOLESTR* ppszW){    ULONG cCharacters;    DWORD dwError;    // If input is null then just return the same.    if (NULL == pszA)    {        *ppszW = NULL;        return NOERROR;    }    // Determine number of wide characters to be allocated for the    // Unicode string.    cCharacters =  strlen(pszA)+1;    // Use of the OLE allocator is required if the resultant Unicode    // string will be passed to another COM component and if that    // component will free it. Otherwise you can use your own allocator.    *ppszW = (LPOLESTR) CoTaskMemAlloc(cCharacters*2);    if (NULL == *ppszW)        return E_OUTOFMEMORY;    // Covert to Unicode.    if (0 == MultiByteToWideChar(CP_ACP, 0, pszA, cCharacters,                  *ppszW, cCharacters))    {        dwError = GetLastError();        CoTaskMemFree(*ppszW);        *ppszW = NULL;        return HRESULT_FROM_WIN32(dwError);    }    return NOERROR;/* * UnicodeToAnsi converts the Unicode string pszW to an ANSI string * and returns the ANSI string through ppszA. Space for the * the converted string is allocated by UnicodeToAnsi. */ HRESULT __fastcall UnicodeToAnsi(LPCOLESTR pszW, LPSTR* ppszA){    ULONG cbAnsi, cCharacters;    DWORD dwError;    // If input is null then just return the same.    if (pszW == NULL)    {        *ppszA = NULL;        return NOERROR;    }    cCharacters = wcslen(pszW)+1;    // Determine number of bytes to be allocated for ANSI string. An    // ANSI string can have at most 2 bytes per character (for Double    // Byte Character Strings.)    cbAnsi = cCharacters*2;    // Use of the OLE allocator is not required because the resultant    // ANSI  string will never be passed to another COM component. You    // can use your own allocator.    *ppszA = (LPSTR) CoTaskMemAlloc(cbAnsi);    if (NULL == *ppszA)        return E_OUTOFMEMORY;    // Convert to ANSI.    if (0 == WideCharToMultiByte(CP_ACP, 0, pszW, cCharacters, *ppszA,                  cbAnsi, NULL, NULL))    {        dwError = GetLastError();        CoTaskMemFree(*ppszA);        *ppszA = NULL;        return HRESULT_FROM_WIN32(dwError);    }    return NOERROR;}

怎么将汉字转换成unicode

unicode编码不需要转换成汉字,因为unicode就是和字符关联的终极编码。windows中只有unicode码可以和字符直接关联,也就是使用国际标准的unicode字符集。中文windowsXp默认的内码是gbk(装过gb18030补丁的话也就变成gb18030),日文系统就是JIS,不同语言版本的windows都有不同的默认内码,这是每个国家的标准化管理局规定的。然后就是页码表的概念,所谓页码表就是把一个用系统默认编码(比如gbk,gb2312)表示的字符映射到对应unicode编码,而每个unicode编码对应着唯一确定的字符。这样就完成了地域性编码到国际标准码再到字符的对应关系。在控制面板-》区域和语言选择-》高级,里面可以看到window提供的所有页码表。

Swift 怎么把unicode编码转成中文

unicode编码不需要转换成汉字,因为unicode就是和字符关联的终极编码。windows中只有unicode码可以和字符直接关联,也就是使用国际标准的unicode字符集。中文windowsXp默认的内码是gbk(装过gb18030补丁的话也就变成gb18030),

如何将字符unicode码转换为实际字符

如果是vb的话可以用chrw()实现unicode字符转换成汉字,用ascw()可以实现汉字转换成unicode码。那如果是好几个字符(字符串)呢?该怎么转换?回答:是的。不过可以像下面这样来操作:dimunicode()st=“字符串“l=len(st)redimunicode(l)fori=0tol-1unicode(i)=ascw(mid(st,i+1,1))nextfori=0tol-1printunicode(i)next这样字符串的所有字符都转换成unicode码并全部放到了数组unicode中了


声明:本文版权归原作者所有,转载文章仅为传播更多信息之目的,如作者信息标记有误,请第一时间联系我们修改或删除,谢谢。

上一篇: linux就该这么学第二版(鸟哥的Linux私房菜:基础学习篇,第二版与第三版有什么区别)

下一篇: require(require的意思)



推荐阅读

网站内容来自网络,如有侵权请联系我们,立即删除! | 软文发布 | 粤ICP备2021106084号