论坛交流
首页办公自动化| 网页制作| 平面设计| 动画制作| 数据库开发| 程序设计| 全部视频教程
应用视频: Windows | Word2007 | Excel2007 | PowerPoint2007 | Dreamweaver 8 | Fireworks 8 | Flash 8 | Photoshop cs | CorelDraw 12
编程视频: C语言视频教程 | HTML | Div+Css布局 | Javascript | Access数据库 | Asp | Sql Server数据库Asp.net  | Flash AS
当前位置 > 文字教程 > Asp.net教程
Tag:静态页面,treeview,gridview,repeater,dataset,sqldatareader,ado.net,上传,三层,ajax,xml,留言本,新闻发布,商城,注入,存储过程,分页,安全,优化,xmlhttp,fso,jmail,application,session,防盗链,stream,无组件,组件,md5,乱码,缓存,加密,验证码,算法,cookies,ubb,正则表达式,水印,索引,日志,压缩,base64,url重写,控件,Web.config,JDBC,函数,内存,PDF,迁移,结构,破解,编译,配置,进程,分词,IIS,触发器,socket,form认证,登录,视频教程

获得汉字字符串的首个拼音字母的缩写

文章类别:Asp.net | 发表日期:2008-10-5 22:08:01

    标题可能不太清楚,实现的功能如下:我爱中国-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                return "D";
 43            }
 44
 45
 46            else if (temp >= 46826 && temp <= 47009)
 47            {
 48                return "E";
 49            }
 50            else if (temp >= 47010 && temp <= 47296)
 51            {
 52                return "F";
 53            }
 54            else if (temp >= 47297 && temp <= 47613)
 55            {
 56                return "G";
 57            }
 58            else if (temp >= 47614 && temp <= 48118)
 59            {
 60                return "H";
 61            }
 62            else if (temp >= 48119 && temp <= 49061)
 63            {
 64                return "J";
 65            }
 66            else if (temp >= 49062 && temp <= 49323)
 67            {
 68                return "K";
 69            }
 70            else if (temp >= 49324 && temp <= 49895)
 71            {
 72                return "L";
 73            }
 74            else if (temp >= 49896 && temp <= 50370)
 75            {
 76                return "M";
 77            }
 78            else if (temp >= 50371 && temp <= 50613)
 79            {
 80                return "N";
 81            }
 82            else if (temp >= 50614 && temp <= 50621)
 83            {
 84                return "O";
 85            }
 86            else if (temp >= 50622 && temp <= 50905)
 87            {
 88                return "P";
 89            }
 90            else if (temp >= 50906 && temp <= 51386)
 91            {
 92                return "Q";
 93            }
 94            else if (temp >= 51387 && temp <= 51445)
 95            {
 96                return "R";
 97            }
 98            else if (temp >= 51446 && temp <= 52217)
 99            {
100                return "S";
101            }
102            else if (temp >= 52218 && temp <= 52697)
103            {
104                return "T";
105            }
106            else if (temp >= 52698 && temp <= 52979)
107            {
108                return "W";
109            }
110            else if (temp >= 52980 && temp <= 53688)
111            {
112                return "X";
113            }
114            else if (temp >= 53689 && temp <= 54480)
115            {
116                return "Y";
117            }
118            else if (temp >= 54481 && temp <= 62289)
119            {
120                return "Z";
121            }
122            else
123            {
124                return c.ToString();
125            }
126        }
127    }
128}
129
http://www.cnblogs.com/jillzhang/archive/2006/10/30/544596.html
上一篇:{技巧}SQL Artisan多表查询和统计 人气:4817
下一篇:{技巧}存储过程的分析 人气:4303
视频教程列表
文章教程搜索
 
Asp.net推荐教程
Asp.net热门教程
看全部视频教程
购买方式/价格
购买视频教程: 咨询客服
tel:15972130058