且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何使用BOM对UTF-16LE字节数组进行编码/解码?

更新时间:2023-11-24 21:27:34

UTF-16字符集名称将始终使用BOM和将使用大/小字节顺序解码数据,但UnicodeBig和UnicodeLittle对于按特定字节顺序进行编码非常有用。使用UTF-16LE或UTF-16BE无BOM - 请参阅此帖子,了解如何使用\ uFEFF手动处理物料清单。有关charset的规范命名,请参见此处字符串名称或(***) Charset 上课。另请注意,只有有限的子集编码绝对需要得到支持。

The "UTF-16" charset name will always encode with a BOM and will decode data using either big/little endianness, but "UnicodeBig" and "UnicodeLittle" are useful for encoding in a specific byte order. Use UTF-16LE or UTF-16BE for no BOM - see this post for how to use "\uFEFF" to handle BOMs manually. See here for canonical naming of charset string names or (preferably) the Charset class. Also take note that only a limited subset of encodings are absolutely required to be supported.