日期:2010-12-02  浏览次数:20469 次

    标题可能不太清楚,实现的功能如下:我爱中国-WAZG
 1。汉字字符与英文字母之间区别
     标准的asc表不包含汉字字符,因为一个asc字符只有1byte,就是8bit,8bit所能代表的数字范围,如果是有符号的好,因该为-128-127,无符号的话,应该为0-255。而我们知道,一个汉字字符,应该占有2个byte,表示范围应该为-32768-32767,所以汉字的asc,举例一段bit:  11002111,11111101它所代表的字符,应该超过了asc所能表述的范围,这时候就会产生溢出。所以占有两个byte的汉字字符的asc码应该为负的。
2.功能实现
  1using System;
  2using System.Collections.Generic;
  3using System.Text;
  4
  5namespace ConsoleApplication1
  6{
  7    class Program
  8    {
  9        static void Main(string[] args)
 10        {
 11            Console.WriteLine(GetChineseFirstChar("我a*%爱你中国"));;
 12        }
 13        static string GetChineseFirstChar(string chineseStr)
 14        {
 15            StringBuilder sb = new StringBuilder();
 16            int length = chineseStr.Length;
 17            for (int i = 0; i < length; i++)
 18            {            
 19                char chineseChar = chineseStr[i];
 20                sb.Append(GetpyChar(chineseChar));
 21            }
 22            return sb.ToString();
 23        }
 24        static string GetpyChar(char c)
 25        {
 26            int ascCode = Microsoft.VisualBasic.Strings.Asc(c);
 27            int temp = 65536 + ascCode;
 28            if (temp >= 45217 && temp <= 45252)
 29            {
 30                return "A";
 31            }
 32            else if (temp >= 45253 && temp <= 45760)
 33            {
 34                return "B";
 35            }
 36            else if (temp >= 45761 && temp <= 46317)
 37            {
 38                return "C";
 39            }
 40            else if (temp >= 46318 && temp <= 46825)
 41            {
 42