U + 00F6的四字节编码(LATIN SMALL LETTER O WITH DIAERESIS)?

时间:2010-04-23 19:11:33

标签: unicode utf-8 internationalization character-encoding

哪个字符编码(或编码组合)代表字符öU+00F6LATIN SMALL LETTER O WITH DIAERESIS或简单地将chr(246)置于ISO-8859-1中)作为四个八位组合chr(195) . chr(63) . chr(194) . chr(164)

1 个答案:

答案 0 :(得分:2)

This page列出了该特定字符的所有各种二进制表示的相当全面的集合,并且它们都没有接近您所拥有的。您确定在文本编码之上没有进行其他转换吗?

如果您认为数据可能已多次编码,请尝试以下操作:

public static IEnumerable<Encoding> FindEncodingPath(char desiredChar, byte[] data)
{
    return FindEncodingPath(new char[] { desiredChar }, data, 5);
}

private static IEnumerable<Encoding> FindEncodingPath(char[] desiredChar, byte[] data, int iterationsLeft)
{
    List<Encoding> encodings = null;

    foreach(Encoding enc in Encoding.GetEncodings())
    {
        byte[] temp = enc.GetBytes(desiredChar);

        bool match = false;

        if(temp.Length == data.Length)
        {
            match = true;

            for(int i = 0; i < data.Length; i++) 
            {
                if(data[i] != temp[i])
                {
                    match = false;
                    break;
                }
            }
        }

        if(match)
        {
            encodings = new List<Encoding>();

            encodings.Add(enc);

            break;
        }
        else if(iterationsLeft > 0)
        {
            IEnumerable<Encoding> tempEnc = FindEncodingPath(desiredChar, temp, iterationsLeft - 1);

            if(tempEnc != null)
            {
                encodings = new List<Encoding>();

                encodings.Add(enc);
                encodings.AddRange(tempEnc);

                break;
            }
        }
    }

    return encodings;
}