获取字符串中的汉字拼音首字母_C#教程-PHP源码
作者:年轮033 | 来源:互联网 | 2018-03-23 03:55
获取字符串中的汉字拼音首字母
获取字符串中的汉字拼音首字母(根据http://blog.csdn.net/iwebsms/archive/2004/09/28/119851.aspx修改)
可能代码比较臃肿,希望有朋友再帮忙改正
//返回给定字符串的首字母
private String IndexCode(String IndexTxt)
{
String _Temp=null;
for(int i=0;i _Temp = _Temp + GetOneIndex( IndexTxt.Substring(i,1) );
return _Temp;
}
//得到单个字符的首字母
private String GetOneIndex(String OneIndexTxt)
{
if(Convert.ToChar(OneIndexTxt)>=0 && Convert.ToChar(OneIndexTxt)<256)
return OneIndexTxt;
else
{
Encoding gb2312 = Encoding.GetEncoding("gb2312");
byte[] unicodeBytes = Encoding.Unicode.GetBytes(OneIndexTxt);
byte[] gb2312Bytes = Encoding.Convert(Encoding.Unicode, gb2312, unicodeBytes);
return GetX(Convert.ToInt32(
String.Format("{0:D2}",Convert.ToInt16(gb2312Bytes[0])-160)
+ String.Format("{0:D2}",Convert.ToInt16(gb2312Bytes[1])-160)
));
}
}
//根据区位得到首字母
private String GetX(int GBCode)
{
if(GBCode >= 1601 && GBCode <1637)return "A";
if(GBCode >= 1637 && GBCode <1833)return "B";
if(GBCode >= 1833 && GBCode <2078)return "C";
if(GBCode >= 2078 && GBCode <2274)return "D";
if(GBCode >= 2274 && GBCode <2302)return "E";
if(GBCode >= 2302 && GBCode <2433)return "F";
if(GBCode >= 2433 && GBCode <2594)return "G";
if(GBCode >= 2594 && GBCode <2787)return "H";
if(GBCode >= 2787 && GBCode <3106)return "J";
if(GBCode >= 3106 && GBCode <3212)return "K";
if(GBCode >= 3212 && GBCode <3472)return "L";
if(GBCode >= 3472 && GBCode <3635)return "M";
if(GBCode >= 3635 && GBCode <3722)return "N";
if(GBCode >= 3722 && GBCode <3730)return "O";
if(GBCode >= 3730 && GBCode <3858)return "P";
if(GBCode >= 3858 && GBCode <4027)return "Q";
if(GBCode >= 4027 && GBCode <4086)return "R";
if(GBCode >= 4086 && GBCode <4390)return "S";
if(GBCode >= 4390 && GBCode <4558)return "T";
if(GBCode >= 4558 && GBCode <4684)return "W";
if(GBCode >= 4684 && GBCode <4925)return "X";
if(GBCode >= 4925 && GBCode <5249)return "Y";
if(GBCode >= 5249 && GBCode <= 5589)return "Z";
if(GBCode >= 5601 && GBCode <= 8794)
{
String CodeData = "cjwgnspgcenegypbtwxzdxykygtpjnmjqmbsgzscyjsyyfpggbzgydywjkgaljswkbjqhyjwpdzlsgmr"
+ "ybywwccgznkydgttngjeyekzydcjnmcylqlypyqbqrpzslwbdgkjfyxjwcltbncxjjjjcxdtqsqzycdxxhgckbphffss"
+ "pybgmxjbbyglbhlssmzmpjhsojnghdzcdklgjhsgqzhxqgkezzwymcscjnyetxadzpmdssmzjjqjyzcjjfwqjbdzbjgd"
+ "nzcbwhgxhqkmwfbpbqdtjjzkqhylcgxfptyjyyzpsjlfchmqshgmmxsxjpkdcmbbqbefsjwhwwgckpylqbgldlcctnma"
+ "eddksjngkcsgxlhzaybdbtsdkdylhgymylcxpycjndqjwxqxfyyfjlejbzrwccqhqcsbzkymgplbmcrqcflnymyqmsqt"
+ "rbcjthztqfrxchxmcjcjlxqgjmshzkbswxemdlckfsydsglycjjssjnqbjctyhbftdcyjdgwyghqfrxwckqkxebpdjpx"
+ "jqsrmebwgjlbjslyysmdxlclqkxlhtjrjjmbjhxhwywcbhtrxxglhjhfbmgykldyxzpplggpmtcbbajjzyljtyanjgbj"
+ "flqgdzyqcaxbkclecjsznslyzhlxlzcghbxzhznytdsbcjkdlzayffydlabbgqszkggldndnyskjshdlxxbcghxyggdj"
+ "mmzngmmccgwzszxsjbznmlzdthcqydbdllscddnlkjyhjsycjlkohqasdhnhcsgaehdaashtcplcpqybsdmpjlpcjaql"
+ "cdhjjasprchngjnlhlyyqyhwzpnccgwwmzffjqqqqxxaclbhkdjxdgmmydjxzllsygxgkjrywzwyclzmcsjzldbndcfc"
+ "xyhlschycjqppqagmnyxpfrkssbjlyxyjjglnscmhcwwmnzjjlhmhchsyppttxrycsxbyhcsmxjsxnbwgpxxtaybgajc"
+ "xlypdccwqocwkccsbnhcpdyznbcyytyckskybsqkkytqqxfcwchcwkelcqbsqyjqcclmthsywhmktlkjlychwheqjhtj"
+ "hppqpqscfymmcmgbmhglgsllysdllljpchmjhwljcyhzjxhdxjlhxrswlwzjcbxmhzqxsdzpmgfcsglsdymjshxpjxom"
+ "yqknmyblrthbcftpmgyxlchlhlzylxgsssscclsldclepbhshxyyfhbmgdfycnjqwlqhjjcywjztejjdhfblqxtqkwhd"
+ "chqxagtlxljxmsljhdzkzjecxjcjnmbbjcsfywkbjzghysdcpqyrsljpclpwxsdwejbjcbcnaytmgmbapclyqbclzxcb"
+ "nmsggfnzjjbzsfqyndxhpcqkzczwalsbccjxpozgwkybsgxfcfcdkhjbstlqfsgdslqwzkxtmhsbgzhjcrglyjbpmljs"
+ "xlcjqqhzmjczydjwbmjklddpmjegxyhylxhlqyqhkycwcjmyhxnatjhyccxzpcqlbzwwwtwbqcmlbmynjcccxbbsnzzl"
+ "jpljxyztzlgcldcklyrzzgqtgjhhgjljaxfgfjzslcfdqzlclgjdjcsnclljpjqdcclcjxmyzftsxgcgsbrzxjqqcczh"
+ "gyjdjqqlzxjyldlbcyamcstylbdjbyregklzdzhldszchznwczcllwjqjjjkdgjcolbbzppglghtgzcygezmycnqcycy"
+ "hbhgxkamtxyxnbskyzzgjzlqjdfcjxdygjqjjpmgwgjjjpkjsbgbmmcjssclpqpdxcdyykypcjddyygywchjrtgcnyql"
+ "dkljczzgzccjgdyksgpzmdlcphnjafyzdjcnmwescsglbtzcgmsdllyxqsxsbljsbbsgghfjlwpmzjnlyywdqshzxtyy"
+ "whmcyhywdbxbtlmswyyfsbjcbdxxlhjhfpsxzqhfzmqcztqcxzxrdkdjhnnyzqqfnqdmmgnydxmjgdhcdycbffallztd"
+ "ltfkmxqzdngeqdbdczjdxbzgsqqddjcmbkxffxmkdmcsychzcmljdjynhprsjmkmpcklgdbqtfzswtfgglyplljzhgjj"
+ "gypzltcsmcnbtjbhfkdhbyzgkpbbymtdlsxsbnpdkleycjnycdykzddhqgsdzsctarlltkzlgecllkjljjaqnbdggghf"
+ "jtzqjsecshalqfmmgjnlyjbbtmlycxdcjpldlpcqdhsycbzsckbzmsljflhrbjsnbrgjhxpdgdjybzgdlgcsezgxlblg"
+ "yxtwmabchecmwyjyzlljjshlgndjlslygkdzpzxjyyzlpcxszfgwyydlyhcljscmbjhblyjlycblydpdqysxktbytdkd"
+ "xjypcnrjmfdjgklccjbctbjddbblblcdqrppxjcglzcshltoljnmdddlngkaqakgjgyhheznmshrphqqjchgmfprxcjg"
+ "dychghlyrzqlcngjnzsqdkqjymszswlcfqjqxgbggxmdjwlmcrnfkkfsyyljbmqammmycctbshcptxxzzsmphfshmclm"
+ "ldjfyqxsdyjdjjzzhqpdszglssjbckbxyqzjsgpsxjzqznqtbdkwxjkhhgflbcsmdldgdzdblzkycqnncsybzbfglzzx"
+ "swmsccmqnjqsbdqsjtxxmbldxcclzshzcxrqjgjylxzfjphymzqqydfqjjlcznzjcdgzygcdxmzysctlkphtxhtlbjxj"
+ "lxscdqccbbqjfqzfsltjbtkqbsxjjljchczdbzjdczjccprnlqcgpfczlclcxzdmxmphgsgzgszzqjxlwtjpfsyaslcj"
+ "btckwcwmytcsjjljcqlwzmalbxyfbpnlschtgjwejjxxglljstgshjqlzfkcgnndszfdeqfhbsaqdgylbxmmygszldyd"
+ "jmjjrgbjgkgdhgkblgkbdmbylxwcxyttybkmrjjzxqjbhlmhmjjzmqasldcyxyqdlqcafywyxqhz";
String _gbcode = GBCode.ToString();
int pos = (Convert.ToInt16(_gbcode.Substring(0,2))-56)*94+Convert.ToInt16(_gbcode.Substring(_gbcode.Length-2,2));
return CodeData.Substring(pos-1,1);
}
return " ";
}
推荐阅读
-
本文回顾了作者初次接触Unicode编码时的经历,并详细探讨了ASCII、ANSI、GB2312、UNICODE以及UTF-8和UTF-16编码的区别和应用场景。通过实例分析,帮助读者更好地理解和使用这些编码。 ...
[详细]
蜡笔小新 2024-11-13 07:33:27
-
mac用于开发使用时间长硬盘会越来越小,速度越来越慢的,亦是花了几分钟研究怎么清理系统的缓存,方法:1,到https:www.omnigroup.commore安装OmniDisk ...
[详细]
蜡笔小新 2024-10-20 14:00:38
-
-
nsitionalENhttp:www.w3.orgTRxhtml1DTDxhtml1-transitional.dtd ...
[详细]
蜡笔小新 2024-10-16 21:41:12
-
[译] OS X 和 iOS 的测绘框架Core Plot 入门教程 ...
[详细]
蜡笔小新 2024-10-16 09:58:13
-
Couldnotbuildmodule“UIKit”问题解决方法:1、UserskyjunLibraryDeveloperXcodeDerivedData目录下文件删除2、设置Al ...
[详细]
蜡笔小新 2024-10-15 18:10:37
-
SoIwanttomakesomethinglikethisusingswiftandxcode:所以我想用swift和xcode制作这样的东西:WhereIget ...
[详细]
蜡笔小新 2024-10-15 11:20:06
-
我正在尝试使SwiftUI中的按钮在文本旁边显示图像。但是,即使不在按钮中时图像 ...
[详细]
蜡笔小新 2024-10-13 21:50:40
-
Xcode7.1使用键盘通知出现以下错误,该怎么解决? ...
[详细]
蜡笔小新 2024-10-13 19:14:29
-
电脑系统从10.11升级到10.11.4真机就运行不了,其他项目都可以,就这个git上的项目不可以,一直报这个错误 ...
[详细]
蜡笔小新 2024-10-10 15:59:42
-
直入主题(此环境配置在Mac下):1、xcode新创建MacOS工程,如下图2、添加 OpenGl.framework GLUT.framework两个系统库3、添加两个工具文件C ...
[详细]
蜡笔小新 2024-10-09 16:21:16
-
导读:本文来自SwiftGG翻译组,作者@walkingway基于苹果Swift官方博客中TedKremenek所撰写的“Swift2.2Released!”文章进行了关于Swift2. ...
[详细]
蜡笔小新 2024-10-09 16:10:18
-
第一次安装Xcode是花了很久,二十多个GB ...
[详细]
蜡笔小新 2024-10-09 13:25:01
-
项目地址:github.comDanie1sDNS…DNSPageViewDNSPageView一个纯Swift的轻量级、灵活且易于使用的pageView框架 ...
[详细]
蜡笔小新 2024-10-08 18:03:51
-
之前做项目时遇到一个问题:使用UITextView显示一段电影的简介,由于字数比较多,所以字体设置的很小,行间距和段间距也很小,一大段文字挤在一起看起来很别扭,想要把行间距调大,结 ...
[详细]
蜡笔小新 2024-09-30 01:14:47
-
BookDescripterAutoLayouttransformsthewayyoucreateiOSuserinterfaces.Asflexibleasitispowerfu ...
[详细]
蜡笔小新 2024-09-26 13:20:23
-