熱點推薦:
您现在的位置: 電腦知識網 >> 操作系統 >> Windows優化 >> 正文

用 C# 通過內碼實現漢字轉化為拼音

2022-06-13   來源: Windows優化 

  其實現的原理就是先將漢字轉化成為內碼然後通過內碼和拼音的對照來查找
  
  詳細的代碼如下所示
  
  public class chspy
  {///
  ///將漢字轉換成為拼音
  ///作者鐵匠(chinahuman)
  ///完成於日早上
  ///

  
  private static int[] pyvalue=new int[]{
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  };
  private static string[] pystr=new string[]{aaianangaobabaibanbangbaobeibenbengbibianbiao
  biebinbingbobucacaicancangcaocecengchachaichanchangchaochechen
  chengchichongchouchuchuaichuanchuangchuichunchuocicongcoucucuancui
  cuncuodadaidandangdaodedengdidiandiaodiedingdiudongdoududuan
  duidunduoeenerfafanfangfeifenfengfofoufugagaiganganggao
  gegeigengenggonggouguguaguaiguanguangguigunguohahaihanhang
  haoheheihenhenghonghouhuhuahuaihuanhuanghuihunhuojijiajian
  jiangjiaojiejinjingjiongjiujujuanjuejunkakaikankangkaokeken
  kengkongkoukukuakuaikuankuangkuikunkuolalailanlanglaolelei
  lenglilialianliangliaolielinlingliulongloululvluanluelunluo
  mamaimanmangmaomemeimenmengmimianmiaomieminmingmiumomoumu
  nanainannangnaoneneinennengninianniangniaonieninningniunong
  nunvnuannuenuoooupapaipanpangpaopeipenpengpipianpiaopie
  pinpingpopuqiqiaqianqiangqiaoqieqinqingqiongqiuququanquequn
  ranrangraorerenrengrirongroururuanruirunruosasaisansang
  saosesensengshashaishanshangshaosheshenshengshishoushushua
  shuaishuanshuangshuishunshuosisongsoususuansuisunsuotatai
  tantangtaotetengtitiantiaotietingtongtoututuantuituntuo
  wawaiwanwangweiwenwengwowuxixiaxianxiangxiaoxiexinxing
  xiongxiuxuxuanxuexunyayanyangyaoyeyiyinyingyoyongyou
  yuyuanyueyunzazaizanzangzaozezeizenzengzhazhaizhanzhang
  zhaozhezhenzhengzhizhongzhouzhuzhuazhuaizhuanzhuangzhuizhunzhuo
  zizongzouzuzuanzuizunzuo};
  public chspy()
  {
  //
  // TODO: 在此處添加構造函數邏輯
  //
  }
  public static string convert(string chrstr)
  {
  byte[] array = new byte[];
  string returnstr=;
  int chrasc=;
  int i = ;
  int i =;
  char[] nowchar=chrstrToCharArray();
  for (int j=;j  {
  array = System.Text.Encoding.Default.GetBytes(nowchar[j].ToString ());
  i1 = (short)(array[0] );
  i2 = (short)(array[1] );
  
  chrasc=i1*256+i2-65536;
  if (chrasc> && chrasc<160)
  {
  returnstr+=nowchar[j];
  }
  else
  {
  for (int i=(pyvalue.Length -1);i>=;i)
  {
  if (pyvalue[i]<=chrasc)
  {
  returnstr+=pystr[i];
  break;
  }
  }
  }
  }
  return returnstr;
  
  }
  }
  

From:http://tw.wingwit.com/Article/os/youhua/201311/10725.html
    推薦文章
    Copyright © 2005-2022 電腦知識網 Computer Knowledge   All rights reserved.