博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
获得汉字字符串的首个拼音字母的缩写
阅读量:7185 次
发布时间:2019-06-29

本文共 2608 字,大约阅读时间需要 8 分钟。

    标题可能不太清楚,实现的功能如下:我爱中国-WAZG
 1。汉字字符与英文字母之间区别
     标准的asc表不包含汉字字符,因为一个asc字符只有1byte,就是8bit,8bit所能代表的数字范围,如果是有符号的好,因该为-128-127,无符号的话,应该为0-255。而我们知道,一个汉字字符,应该占有2个byte,表示范围应该为-32768-32767,所以汉字的asc,举例一段bit:  11002111,11111101它所代表的字符,应该超过了asc所能表述的范围,这时候就会产生溢出。所以占有两个byte的汉字字符的asc码应该为负的。
2.功能实现
  1
None.gif
using
 System;
  2
None.gif
using
 System.Collections.Generic;
  3
None.gif
using
 System.Text;
  4
None.gif
  5
None.gif
namespace
 ConsoleApplication1
  6
ExpandedBlockStart.gifContractedBlock.gif
dot.gif
{
  7InBlock.gif    class Program
  8ExpandedSubBlockStart.gifContractedSubBlock.gif    dot.gif{
  9InBlock.gif        static void Main(string[] args)
 10ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
 11InBlock.gif            Console.WriteLine(GetChineseFirstChar("我a*%爱你中国"));;
 12ExpandedSubBlockEnd.gif        }
 13InBlock.gif        static string GetChineseFirstChar(string chineseStr)
 14ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
 15InBlock.gif            StringBuilder sb = new StringBuilder();
 16InBlock.gif            int length = chineseStr.Length;
 17InBlock.gif            for (int i = 0; i < length; i++)
 18ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{             
 19InBlock.gif                char chineseChar = chineseStr[i];
 20InBlock.gif                sb.Append(GetpyChar(chineseChar));
 21ExpandedSubBlockEnd.gif            }
 22InBlock.gif            return sb.ToString();
 23ExpandedSubBlockEnd.gif        }
 24InBlock.gif        static string GetpyChar(char c)
 25ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
 26InBlock.gif            int ascCode = Microsoft.VisualBasic.Strings.Asc(c);
 27InBlock.gif            int temp = 65536 + ascCode;
 28InBlock.gif            if (temp >= 45217 && temp <= 45252)
 29ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
 30InBlock.gif                return "A";
 31ExpandedSubBlockEnd.gif            }
 32InBlock.gif            else if (temp >= 45253 && temp <= 45760)
 33ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
 34InBlock.gif                return "B";
 35ExpandedSubBlockEnd.gif            }
 36InBlock.gif            else if (temp >= 45761 && temp <= 46317)
 37ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
 38InBlock.gif                return "C";
 39ExpandedSubBlockEnd.gif            }
 40InBlock.gif            else if (temp >= 46318 && temp <= 46825)
 41ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
 42InBlock.gif                return "D";
 43ExpandedSubBlockEnd.gif            }
 44InBlock.gif
 45InBlock.gif
 46InBlock.gif            else if (temp >= 46826 && temp <= 47009)
 47ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
 48InBlock.gif                return "E";
 49ExpandedSubBlockEnd.gif            }
 50InBlock.gif            else if (temp >= 47010 && temp <= 47296)
 51ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
 52InBlock.gif                return "F";
 53ExpandedSubBlockEnd.gif            }
 54InBlock.gif            else if (temp >= 47297 && temp <= 47613)
 55ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
 56InBlock.gif                return "G";
 57ExpandedSubBlockEnd.gif            }
 58InBlock.gif            else if (temp >= 47614 && temp <= 48118)
 59ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
 60InBlock.gif                return "H";
 61ExpandedSubBlockEnd.gif            }
 62InBlock.gif            else if (temp >= 48119 && temp <= 49061)
 63ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
 64InBlock.gif                return "J";
 65ExpandedSubBlockEnd.gif            }
 66InBlock.gif            else if (temp >= 49062 && temp <= 49323)
 67ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
 68InBlock.gif                return "K";
 69ExpandedSubBlockEnd.gif            }
 70InBlock.gif            else if (temp >= 49324 && temp <= 49895)
 71ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
 72InBlock.gif                return "L";
 73ExpandedSubBlockEnd.gif            }
 74InBlock.gif            else if (temp >= 49896 && temp <= 50370)
 75ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
 76InBlock.gif                return "M";
 77ExpandedSubBlockEnd.gif            }
 78InBlock.gif            else if (temp >= 50371 && temp <= 50613)
 79ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
 80InBlock.gif                return "N";
 81ExpandedSubBlockEnd.gif            }
 82InBlock.gif            else if (temp >= 50614 && temp <= 50621)
 83ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
 84InBlock.gif                return "O";
 85ExpandedSubBlockEnd.gif            }
 86InBlock.gif            else if (temp >= 50622 && temp <= 50905)
 87ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
 88InBlock.gif                return "P";
 89ExpandedSubBlockEnd.gif            }
 90InBlock.gif            else if (temp >= 50906 && temp <= 51386)
 91ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
 92InBlock.gif                return "Q";
 93ExpandedSubBlockEnd.gif            }
 94InBlock.gif            else if (temp >= 51387 && temp <= 51445)
 95ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
 96InBlock.gif                return "R";
 97ExpandedSubBlockEnd.gif            }
 98InBlock.gif            else if (temp >= 51446 && temp <= 52217)
 99ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
100InBlock.gif                return "S";
101ExpandedSubBlockEnd.gif            }
102InBlock.gif            else if (temp >= 52218 && temp <= 52697)
103ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
104InBlock.gif                return "T";
105ExpandedSubBlockEnd.gif            }
106InBlock.gif            else if (temp >= 52698 && temp <= 52979)
107ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
108InBlock.gif                return "W";
109ExpandedSubBlockEnd.gif            }
110InBlock.gif            else if (temp >= 52980 && temp <= 53688)
111ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
112InBlock.gif                return "X";
113ExpandedSubBlockEnd.gif            }
114InBlock.gif            else if (temp >= 53689 && temp <= 54480)
115ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
116InBlock.gif                return "Y";
117ExpandedSubBlockEnd.gif            }
118InBlock.gif            else if (temp >= 54481 && temp <= 62289)
119ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
120InBlock.gif                return "Z";
121ExpandedSubBlockEnd.gif            }
122InBlock.gif            else
123ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
124InBlock.gif                return c.ToString();
125ExpandedSubBlockEnd.gif            }
126ExpandedSubBlockEnd.gif        }
127ExpandedSubBlockEnd.gif    }
128ExpandedBlockEnd.gif}
129
None.gif
3.文件:
      
你可能感兴趣的文章
《Kotlin 极简教程 》第4章 基本数据类型与类型系统
查看>>
2012春晚十大流行语
查看>>
XP下关于安装.net 3.5/4.0 报错:安装未完成
查看>>
Collections类中常用方法总结
查看>>
我的友情链接
查看>>
五大主流手机操作系统
查看>>
Android 数据查询query函数参数解析
查看>>
PHP 方法重载介绍
查看>>
教会你Redhat Enterprise Linux关闭SELinux
查看>>
搭建一个git 私有仓库
查看>>
网格部件如何实现列内容的自动换行
查看>>
多个USB短信猫,启动短信猫后台程序总是有几个不能连接
查看>>
Android分享笔记(5) Android 与 JS 交互
查看>>
联机插件连接中心无法打开或者打开时间很长
查看>>
Mesos:服务发现与负载均衡
查看>>
Cisco ASA SSL××× configturation
查看>>
《你的灯亮着么》每年读一次--摘句
查看>>
单例的实现方式
查看>>
配置本地host,实现本地域名解析设置
查看>>
js总结
查看>>