VB.net 2010 视频教程 VB.net 2010 视频教程 python基础视频教程
SQL Server 2008 视频教程 c#入门经典教程 Visual Basic从门到精通视频教程
当前位置:
首页 > Python基础教程 >
  • C#教程之C#判断文件编码——常用字法

 使用中文写文章,当篇幅超过一定程度,必然会使用到诸如:“的”、“你”、“我”这样的常用字。本类思想便是提取中文最常用的一百个字,使用中文世界常用编码(主要有GBKGB2312GB18030UTF-8UTF-32UnicodeBigEndianUnicodeUTF-7等)获得其编码字节,以其为搜索词到目标流进行查找,如果查找得到则表示该流使用此种编码。显而易见此类不适用于小篇幅。

复制代码
using System.Collections.Generic;
using System.IO;
using System.Text;

namespace YunShenBuZhiChu.MiMaBenJiaMiFa
{
    /// <summary>
    /// 文字编码检测。
    /// 用于检测一篇文章使用什么编码方式进行编码。
    /// </summary>
    public class StreamBianMaJianCe
    {
        /// <summary>
        /// BigEndianUnicode编码高频汉字编码
        /// </summary>
        private List<byte[]> _BigEndianUnicodeGaoPinZiFuBianMaLsit = new List<byte[]>()
        {
            new byte[2]{118,132},new byte[2]{78,0},new byte[2]{86,253},new byte[2]{87,40},new byte[2]{78,186},new byte[2]{78,134},new byte[2]{103,9},new byte[2]{78,45},
            new byte[2]{102,47},new byte[2]{94,116},new byte[2]{84,140},new byte[2]{89,39},new byte[2]{78,26},new byte[2]{78,13},new byte[2]{78,58},new byte[2]{83,209},
            new byte[2]{79,26},new byte[2]{93,229},new byte[2]{126,207},new byte[2]{78,10},new byte[2]{87,48},new byte[2]{94,2},new byte[2]{137,129},new byte[2]{78,42},
            new byte[2]{78,167},new byte[2]{143,217},new byte[2]{81,250},new byte[2]{136,76},new byte[2]{79,92},new byte[2]{117,31},new byte[2]{91,182},new byte[2]{78,229},
            new byte[2]{98,16},new byte[2]{82,48},new byte[2]{101,229},new byte[2]{108,17},new byte[2]{103,101},new byte[2]{98,17},new byte[2]{144,232},new byte[2]{91,249},
            new byte[2]{143,219},new byte[2]{89,26},new byte[2]{81,104},new byte[2]{94,250},new byte[2]{78,214},new byte[2]{81,108},new byte[2]{95,0},new byte[2]{78,236},
            new byte[2]{87,58},new byte[2]{92,85},new byte[2]{101,246},new byte[2]{116,6},new byte[2]{101,176},new byte[2]{101,185},new byte[2]{78,59},new byte[2]{79,1},
            new byte[2]{141,68},new byte[2]{91,158},new byte[2]{91,102},new byte[2]{98,165},new byte[2]{82,54},new byte[2]{101,63},new byte[2]{109,78},new byte[2]{117,40},
            new byte[2]{84,12},new byte[2]{78,142},new byte[2]{108,213},new byte[2]{154,216},new byte[2]{149,127},new byte[2]{115,176},new byte[2]{103,44},new byte[2]{103,8},
            new byte[2]{91,154},new byte[2]{83,22},new byte[2]{82,160},new byte[2]{82,168},new byte[2]{84,8},new byte[2]{84,193},new byte[2]{145,205},new byte[2]{81,115},
            new byte[2]{103,58},new byte[2]{82,6},new byte[2]{82,155},new byte[2]{129,234},new byte[2]{89,22},new byte[2]{128,5},new byte[2]{83,58},new byte[2]{128,253},
            new byte[2]{139,190},new byte[2]{84,14},new byte[2]{92,49},new byte[2]{123,73},new byte[2]{79,83},new byte[2]{78,11},new byte[2]{78,7},new byte[2]{81,67},
            new byte[2]{121,62},new byte[2]{143,199},new byte[2]{82,77},new byte[2]{151,98},new byte[2]{48,2},new byte[2]{255,12},new byte[2]{255,31},new byte[2]{255,1}
        };
        /// <summary>
        /// UTF8编码高频汉字编码
        /// </summary>
        private List<byte[]> _UTF8GaoPinZiFuBianMaLsit = new List<byte[]>()
        {
            new byte[3]{231,154,132},new byte[3]{228,184,128},new byte[3]{229,155,189},new byte[3]{229,156,168},new byte[3]{228,186,186},new byte[3]{228,186,134},
            new byte[3]{230,156,137},new byte[3]{228,184,173},new byte[3]{230,152,175},new byte[3]{229,185,180},new byte[3]{229,146,140},new byte[3]{229,164,167},
            new byte[3]{228,184,154},new byte[3]{228,184,141},new byte[3]{228,184,186},new byte[3]{229,143,145},new byte[3]{228,188,154},new byte[3]{229,183,165},
            new byte[3]{231,187,143},new byte[3]{228,184,138},new byte[3]{229,156,176},new byte[3]{229,184,130},new byte[3]{232,166,129},new byte[3]{228,184,170},
            new byte[3]{228,186,167},new byte[3]{232,191,153},new byte[3]{229,135,186},new byte[3]{232,161,140},new byte[3]{228,189,156},new byte[3]{231,148,159},
            new byte[3]{229,174,182},new byte[3]{228,187,165},new byte[3]{230,136,144},new byte[3]{229,136,176},new byte[3]{230,151,165},new byte[3]{230,176,145},
            new byte[3]{230,157,165},new byte[3]{230,136,145},new byte[3]{233,131,168},new byte[3]{229,175,185},new byte[3]{232,191,155},new byte[3]{229,164,154},
            new byte[3]{229,133,168},new byte[3]{229,187,186},new byte[3]{228,187,150},new byte[3]{229,133,172},new byte[3]{229,188,128},new byte[3]{228,187,172},
            new byte[3]{229,156,186},new byte[3]{229,177,149},new byte[3]{230,151,182},new byte[3]{231,144,134},new byte[3]{230,150,176},new byte[3]{230,150,185},
            new byte[3]{228,184,187},new byte[3]{228,188,129},new byte[3]{232,181,132},new byte[3]{229,174,158},new byte[3]{229,173,166},new byte[3]{230,138,165},
            new byte[3]{229