• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

根据区位得到汉字拼音首字母(c#)

原作者: [db:作者] 来自: [db:来源] 收藏 邀请
using System;
using System.Text;

namespace Code
{
 /// <summary>
 /// SearchCode 的摘要说明。
 /// </summary>
 public class SearchCode
 {
  public SearchCode()
  {
   //
   // TODO: 在此处添加构造函数逻辑
   //
  }
/// <summary>
/// 返回给定字符串的首字母
/// </summary>
/// <param name="IndexTxt">字符串</param>
/// <returns></returns>
  public String IndexCode(String IndexTxt)
  {
   String _Temp=null;
   for(int i=0;i<IndexTxt.Length;i++)
    _Temp = _Temp + GetOneIndex( IndexTxt.Substring(i,1) );
   return _Temp;
  }

/// <summary>
/// 返回给定字符串的第一个字的首字母
/// </summary>
/// <param name="str">字符串</param>
/// <returns></returns>
public String OneIndexCode(String str)
{
return GetOneIndex( str.Substring(0,1));
}


  //得到单个字符的首字母
  private String GetOneIndex(String OneIndexTxt)
  {
   if(Convert.ToChar(OneIndexTxt)>=0 && Convert.ToChar(OneIndexTxt)<256)
    return OneIndexTxt.ToUpper();
   else
   {
    Encoding gb2312 = Encoding.GetEncoding("gb2312");
    byte[] unicodeBytes = Encoding.Unicode.GetBytes(OneIndexTxt);
    byte[] gb2312Bytes = Encoding.Convert(Encoding.Unicode, gb2312, unicodeBytes);
    try
    {
     return GetX(Convert.ToInt32(
      String.Format("{0:D2}",Convert.ToInt16(gb2312Bytes[0])-160)
      + String.Format("{0:D2}",Convert.ToInt16(gb2312Bytes[1])-160)
      ));
    }
    catch(Exception ex)
    {
     return "";
    }
   }

  }


/// <summary>
/// 根据区位得到汉字首字母
/// </summary>
/// <param name="GBCode">区位码</param>
/// <returns></returns>
  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 " ";
  }

 }
}

鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C#获取属性名发布时间:2022-07-18
下一篇:
怎样用C语言编写病毒(二)发布时间:2022-07-18
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap