use a custom encoding or add custom characters

前端 未结 1 2007
终归单人心
终归单人心 2021-01-21 21:49

Is there anyway i can use some custom encoding or convert some base16 characters (two bytes chars as in japanese SHIFT-JIS) when reading them using binaryreader ? i mean, while

相关标签:
1条回答
  • 2021-01-21 22:27

    I think you want to implement your own Encoding and Decoding, so the problem is related to how you implement them, that depends on your algorithm. The default Encoding supports only popular encodings such as Unicode, BigEndianUnicode, UTF-8, .... I suggested that you don't need any kind of custom Encoding, as you can see Encoding is just a class with some methods to perform the actual encoding and decoding, it helps you a lot in handling with the well-known, popular encodings Unicode, ... but for your own Encoding, you must implement almost all the core functions like this:

    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
    }
    

    Hope it helps!

    0 讨论(0)
提交回复
热议问题