使用自定义编码或添加自定义字符

无论如何,当使用二进制读取器读取它们时,我可以使用一些自定义编码或转换一些base16字符(日语SHIFT-JIS中的两个字节字符)? 我的意思是,在读取它们时,如果有一个0x00ff,它会在读取和写入时将其转换为“\ et”(编辑文件,并使用二进制文件写入)。

我想你想实现自己的编码和解码,所以问题与你如何实现它们有关,这取决于你的算法。 默认Encoding仅支持流行的编码,如Unicode, BigEndianUnicode, UTF-8, ... 我建议您不需要任何类型的自定义编码,因为您可以看到Encoding只是一个类,有一些方法来执行实际的encodingdecoding ,它可以帮助您处理众所周知的,流行的编码Unicode ,…但是对于您自己的编码,您必须实现几乎所有的核心function,如下所示:

 public class CustomEncoding : Encoding { //NOTE: There are some abstract members requiring you to implement or declare in this derived class. public override byte[] GetBytes(string s) { //Your code goes here } public override string GetString(byte[] bytes) { //Your code goes here } //And many other virtual (overridable) methods which you can override to implement your custom Encoding fully } 

希望能帮助到你!