Encoding.Convert Unicode 到代码页 864

Encoding.Convert Unicode to code page 864

我正在尝试使用 C# 中的 Encoding.Convert 方法,使用以下代码将字符串从编码 1256 转换为 864(均为阿拉伯语)。

    static void example()
    {
        string unicodeString = "ابتثجحخدذرزسشصضطظعغفقكلمنهوي";
        // Create two different encodings.
        Encoding cp1256 = Encoding.GetEncoding(1256);
        Encoding unicode = Encoding.Unicode;

        // Convert the string into a byte array. 
        byte[] unicodeBytes = unicode.GetBytes(unicodeString);

        // Perform the conversion from one encoding to the other. 
        byte[] cp1256Bytes = Encoding.Convert(unicode, cp1256, unicodeBytes);
        //                              ^
        //                              |
        //                           Above convert works

        Encoding cp864 = Encoding.GetEncoding(864);
        byte[] cp864bytes = Encoding.Convert(cp1256, cp864, cp1256Bytes);
        //Above convert does not work and it returns an array of ?

        string cp864String = cp864.GetString(cp864bytes);

        // Display the strings created before and after the conversion.
        Console.WriteLine("Original string: {0}", unicodeString);
        Console.WriteLine("CP864 converted string: {0}", cp864String);

    }

从 UNICODE 到 1256 的转换工作正常,我得到了所有字符,但是,当我从 1256 转换到 864 时,我得到了问号字符 (?)。

有什么建议吗

这个来自 here

Maybe Encoding.GetEncoding(864).GetBytes is not supported by Operating System. But you can implement your own conversion from characters to bytes using this table:

http://www.ascii.ca/cp864.htm.