日期:2014-05-19  浏览次数:20516 次

|M| 哪里有比较准确的汉字转首拼音的代码啊
哪里有比较准确的
汉字转首拼音的代码啊
以下是幕白兄的代码
http://community.csdn.net/Expert/topic/5409/5409486.xml?temp=6.995791E-02
提的代码
但是在转"北京故宫"的时候转成bggg   而不是bjgg

谢谢 有没有比较准的(最好很准的呵呵) 谢谢了

------解决方案--------------------
找个字库,放到数据库里!

------解决方案--------------------
我有个拼音、汉字数据库,有56698条记录!
需要的话,告诉我,发给你!
------解决方案--------------------
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
/*
* 说明:此类用于将一个字符串找出首字声母,用法:ChineseConvert.UtilIndexCode(str);
*
*
*/
/// <summary>
/// ChineseConvert 的摘要说明
/// </summary>
public class ChineseConvert
{
public ChineseConvert()
{
}
/// <summary>
/// 返回字符串的首写字母字符串
/// </summary>
/// <param name= "IndexTxt "> 需得到首写字母的字符串 </param>
/// <returns> </returns>
public static String UtilIndexCode(String IndexTxt)
{
string _Temp = null;
for (int i = 0; i < IndexTxt.Length; i++)
_Temp = _Temp + GetOneIndex(IndexTxt.Substring(i, 1));
return _Temp;
}

//得到单个字符的首字母
private static String GetOneIndex(String OneIndexTxt)
{
if (Convert.ToChar(OneIndexTxt) > = 0 && Convert.ToChar(OneIndexTxt) < 256)
return OneIndexTxt;
else
return GetGbkX(OneIndexTxt);
}

//根据汉字拼音排序得到首字母
private static string GetGbkX(string str)
{
if (str.CompareTo( "吖 ") < 0)
{
return str;
}
if (str.CompareTo( "八 ") < 0)
{
return "A ";
}

if (str.CompareTo( "嚓 ") < 0)
{
return "B ";
}

if (str.CompareTo( "咑 ") < 0)
{
return "C ";
}
if (str.CompareTo( "妸 ") < 0)
{
return "D ";
}
if (str.CompareTo( "发 ") < 0)
{
return "E ";
}
if (str.CompareTo( "旮 ") < 0)
{
return "F ";
}
if (str.CompareTo( "铪 ") < 0)
{
return "G ";
}
if (str.CompareTo( "讥 ") < 0)
{
return "H ";
}
if (str.CompareTo( "咔 ") < 0)
{
return "J ";
}
if (str.CompareTo( "垃 ") < 0)
{
return "K ";
}
if (str.CompareTo( "嘸 ") < 0)
{
return "L ";
}
if (str.CompareTo( "拏 ") < 0)
{
return "M ";
}
if (str.CompareTo( "噢 ") < 0)
{
return "N ";
}