No UTF-32 big-endian in C#?

拥有回忆 提交于 2019-12-05 06:44:12

It does support big endian on UTF-32. Just create the encoding yourself using the overloaded constructor:

Encoding e = new UTF32Encoding(true /*bigEndian*/, true /*byteOrderMark*/);

The encodings predefined as static on Encoding aren't an exhaustive list. You can create much and much more other encodings.

//https://docs.microsoft.com/en-us/dotnet/api/system.text.encoding?view=netframework-4.7.2
//12000 utf-32  Unicode (UTF-32)    ✓   ✓
//12001 utf-32BE    Unicode (UTF-32 Big endian)
const string strUniRepChr = "�"; //Unicode Character 'REPLACEMENT CHARACTER' (U+FFFD)
Encoding cpUTF32 = Encoding.GetEncoding(12000,
                   new EncoderReplacementFallback(strUniRepChr),
                   new DecoderReplacementFallback(strUniRepChr) );
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!