当前位置: 移动技术网 > IT编程>开发语言>c# > C#实现汉字转换为拼音缩写的代码

C#实现汉字转换为拼音缩写的代码

2019年07月18日  | 移动技术网IT编程  | 我要评论

本文实例为大家分享了c#汉字转换为拼音缩写的实现代码,供大家参考,具体内容如下

using system;
using system.configuration;
using system.data;
using system.web;
using system.web.security;
using system.web.ui;
using system.web.ui.htmlcontrols;
using system.web.ui.webcontrols;
using system.web.ui.webcontrols.webparts; 

public partial class _default : system.web.ui.page
{
 protected void page_load(object sender, eventargs e)
 {
  response.write(getpystring("中华人民共和国"));
 }
 public string getpystring(string str)

 {

  string tempstr = "";

  foreach (char c in str)

  {

   if ((int)c >= 33 && (int)c <= 126)

   {//字母和符号原样保留 

    tempstr += c.tostring();

   }

   else

   {//累加拼音声母 

    tempstr += getpychar(c.tostring());

   }

  }

  return tempstr;

 }

 /// 

 /// 取单个字符的拼音声母 

 /// 

 /// 要转换的单个汉字 

 /// 拼音声母 

 public string getpychar(string c)

 {

  byte[] array = new byte[2];

  array = system.text.encoding.default.getbytes(c);
  int i = (short)(array[0] - '\0') * 256 + ((short)(array[1] - '\0'));
  if (i < 0xb0a1) return "*";
  if (i < 0xb0c5) return "a";
  if (i < 0xb2c1) return "b";
  if (i < 0xb4ee) return "c";
  if (i < 0xb6ea) return "d";
  if (i < 0xb7a2) return "e";
  if (i < 0xb8c1) return "f";
  if (i < 0xb9fe) return "g";
  if (i < 0xbbf7) return "h";
  if (i < 0xbfa6) return "g";
  if (i < 0xc0ac) return "k";
  if (i < 0xc2e8) return "l";
  if (i < 0xc4c3) return "m";
  if (i < 0xc5b6) return "n";
  if (i < 0xc5be) return "o";
  if (i < 0xc6da) return "p";
  if (i < 0xc8bb) return "q";
  if (i < 0xc8f6) return "r";
  if (i < 0xcbfa) return "s";
  if (i < 0xcdda) return "t";
  if (i < 0xcef4) return "w";
  if (i < 0xd1b9) return "x";
  if (i < 0xd4d1) return "y";
  if (i < 0xd7fa) return "z";
  return "*";

 }

}

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持移动技术网。

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网