最近小弟编写一个蜘蛛程序,但是抓的文本实在是五花八门,我只想要中文字符却不知道该怎么办,
还有WebRequest类怎么指定编码啊,我下的好多都是乱吗

解决方案 »

  1.   

    判断字符 在 UNICODE 表中的区位, 一般 汉字 在一个特定区域 Char 其实是 2 个字节 所以可以转化成 short char c = ...
      Int16 unicode = Convert.ToInt16(   c  );
      

  2.   

    看错了你的题目 , 不好意思             String html = "";
                html = Encoding.GetEncoding("GB2312").GetString( 字节数组  );
      

  3.   

    C#中的char类别是占两字节的,16位,可处理所有unicode,所以,你可以通过判断
    ASCII值的方法取得string str = "tthisfll这AAl是lll汉。/字";
    for(int i=0;i<str.Length;++i)
    {
    if ( (str[i] <= '酨') && (str[i] >= '啊'))
    {
    Console.WriteLine("中文:" + str[i]);
    }
    } 以上代码输出:中文:这
    中文:是
    中文:汉
    中文:字
      

  4.   

    上面代码还不够精确,可以用汉字区位码进行判断,区位码表从16到87区是汉字。
    我写了一个函数可以判断是不是汉字。我够热心了吧。bool IsChineseChar(char ch)
    {
    byte[] bytes = System.Text.Encoding.GetEncoding("gb2312").GetBytes(ch.ToString());

    if (bytes.Length != 2)
    {
    return false;
    } int zone = bytes[0];
    int num  = bytes[1];

    return (zone >= 0xB0 && zone <=0xF7) && (num >0xA0 && num<0xFD);
    }