zoukankan      html  css  js  c++  java
  • 6.2. Encoding

    Encoding:ICloneable

    System.Text abstract class Encoding:ICloneable
    封装了char[] 和byte[] 在不同的编码中转换的细节
    

    abstract method

    1. public abstract int GetByteCount(char[] chars, int index, int count);
        //计算对指定字符数组中的一组字符进行编码所产生的字节数
    2. public abstract int GetCharCount(byte[] bytes, int index, int count);
        //计算对字节序列(从指定字节数组开始)进行解码所产生的字符数。
    
    3. public abstract int GetBytes(char[] chars, int charIndex, int charCount,
            byte[] bytes, int byteIndex);
        //将指定字符数组中的一组字符编码为指定的字节数组
    4. public abstract int GetChars(byte[] bytes, int byteIndex, int byteCount,
                                       char[] chars, int charIndex);
        //将指定字节数组中的字节序列解码为指定的字符数组
    
    5. public abstract int GetMaxByteCount(int charCount); //计算对指定数目的字符进行编码所产生的最大字节数
    6. public abstract int GetMaxCharCount(int byteCount); //计算对指定数目的字节进行解码时所产生的最大字符数
    

    GetBytes(),GetChars()

    这两个abstract方法,或则他们的重载方式的virtual方法,本质都是调用这两个abstract方法
    而所有不同的编码方案又分别实现了这两个方法,就实现了char[] 到byte[] 在不同编码方案中的实现
    
    string和char[]的转换时很简单的所以,也就完成了string到char[] 的转换
    
    我觉得编码转化应该是先得到string,然后得到新编码后的byte[],再得到新编码后的string,虽然看到的内容可能是一样的,但是存储的文件大小或者说string的大小是不同的,不同的utf编码之间最重要的区别是占用的大小
    

    GetString

    GetString 其实是先得到char[],然后调用new string() 得到的,本质上是得到char[]
    

    GetEncodings()-> EncodingInfo[]

    在.net core 1.1中还没有这个方法
    EncodingInfo实例每一个都有一个GetEncoding(),可以用来遍历所有的编码方案,虽然好像编程的时候一般没什么用吧
    

    Child class

    12 个子类,12种编码
        ASCIIEncoding
        UTF7Encoding
        UTF8Encoding
        UnicodeEncoding
        UTF32Encoding
        DBCSCodePageEncoding
        EUCJPEncoding
        GB18030Encoding
        ISCIIEncoding
        ISO2022Encoding
        Latin1Encoding
        SBCSCodePageEncoding
    这就是
  • 相关阅读:
    python2的比较函数,cmp
    快速排序
    如果a,b,c为自然数,a+b+c=1000,a方+b方=c方,求出abc可能的组合(python实现)
    python之join
    python之functools partial
    Python 3 iter函数用法简述
    python线程之condition
    python 线程 event
    getattr getattribute setattr hasattr delattr
    Properties类
  • 原文地址:https://www.cnblogs.com/zhangrCsharp/p/7695583.html
Copyright © 2011-2022 走看看