详细链接:/?spm=a1z38n.10677092.card.11.594c1debsAGeak
using Microsoft.International.Converters.PinYinConverter;
(引用的.bll文件到本人的主页下载-->ChnCharInfo.bll)
#region 中文名转换成英文名/// <summary>/// 中文名转换成英文名/// </summary>/// <param name="xm">中文</param>/// <returns></returns>protected static string ToConvertEnglishName(string xm){string result = "", temp = "";char[] items = xm.ToCharArray();for (int i = 0; i < items.Length; i++) // 遍历每个源字符{temp = GetPinyin(items[i].ToString());if (i >= 2)result += temp;if (i == 0)result += (String.Format("{0}{1} ", temp.Substring(0, 1).ToUpper(), temp.Substring(1).ToLower()));if (i == 1)result += (String.Format("{0}{1}", temp.Substring(0, 1).ToUpper(), temp.Substring(1).ToLower()));}return result;}/// <summary> /// 汉字转化为拼音/// </summary> /// <param name="str">汉字</param> /// <returns>全拼</returns> public static string GetPinyin(string str){string r = string.Empty;foreach (char obj in str){try{ChineseChar chineseChar = new ChineseChar(obj);string t = chineseChar.Pinyins[0].ToString();r += t.Substring(0, t.Length - 1);}catch{r += obj.ToString();}}return r.ToLower();}#endregion
如果觉得《中文名转换成英文名(c#)》对你有帮助,请点赞、收藏,并留下你的观点哦!