我们如何将Unicode PUA转换为Unicode(或十六进制) [英] How do we convert Unicode PUA to Unicode(or hexadecimal)

查看:173
本文介绍了我们如何将Unicode PUA转换为Unicode(或十六进制)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





如下面的链接所示,

http://officeopenxml.com/WPtextSpecialContent-symbol.php



报价:



在通过将F000添加到字符值创建的Unicode字符值中,从而将值转移到Unicode专用区域。这样做是为了允许与传统字处理格式的互操作性。因此,在示例中在上面,char属性的值是F034,因此我们将通过从F034中删除F000来获取字符值,以获得Wingdings字体中十六进制值0x34处的字符(或作为十进制值的52)。



我们如何将Unicode私有使用区域转换为Unicode字符(或十六进制值)?



例如,

我需要将Unicode PUAF0E9转换为其等效的unicode。

Hi,

As refereced from the below link,
http://officeopenxml.com/WPtextSpecialContent-symbol.php

quotes:

"In a Unicode character value created by adding F000 to the character value, thereby shifting the value into the Unicode private use area. This is done to allow interoperability with legacy word processing formats. So, in the example above, the value of the char attribute is F034, and so we would obtain the character value by removing F000 from F034 to obtain the character at the hexadecimal value 0x34 in the Wingdings font (or 52 as a decimal value)."

How do we convert Unicode private use area to Unicode character(or hexadecimal value)?

For example,
I need to convert Unicode PUA "F0E9" to its equivalent unicode.

推荐答案

如果我正确的话在您的查询中解释引用,以下代码应该有效。

1.您需要将字符转换为2字节数组

2.然后您需要操作第一个字节

3.最后你需要将操纵的字节转换成Unicode字符



If I correctly interpret quotation in your query, the following code should work.
1. You need to convert character to 2 bytes array
2. Then you need to manipulate first byte
3. Finally you need convert manipulated bytes to Unicode character

private char fromPUA(char PUAChar)
{
    byte[] bytes = Encoding.Unicode.GetBytes(new char[] { PUAChar });
    bytes[1] = 0;
    return Encoding.Unicode.GetChars(bytes)[0];

}
private char toPUA(char input)
{

    byte[] bytes= Encoding.Unicode.GetBytes(new char[] {input});
    bytes[1] = 0xF0;
    return Encoding.Unicode.GetChars(bytes)[0];

}


如果innput是一个字符串,则以下内容应该有效:



If innput is a string the follwing should work:

private char fromPUA(string PUAChar)
 {
     //1. convert input string to the numerixc format
     UInt32 asNumber = Convert.ToUInt32(PUAChar, 16);

     //2. filter out PUA byte
     asNumber = 0Xff & asNumber;

     //3. Return Unicode character
     return  (char)asNumber;
 }







用法:



char c = fromPUA(F061);




usage:

char c = fromPUA("F061");


这篇关于我们如何将Unicode PUA转换为Unicode(或十六进制)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆