/// <summary> /// 汉字转拼音缩写 (字符串) (小写) /// </summary> /// <param name="str">要转换的汉字字符串</param> /// <returns>拼音缩写</returns> public static string GetSpellStringLower(string str) { string text = ""; for (int i = 0; i < str.Length; i++) { char c = str[i]; if (c >= '!' && c <= '~') { text += c.ToString(); } else { text += Chinese2Spell.GetSpellCharLower(c.ToString()); } } return(text); }
/// <summary> /// 汉字转拼音缩写 (字符串) (小写) (空格间隔) /// </summary> /// <param name="str">要转换的汉字字符串</param> /// <returns>拼音缩写</returns> public static string GetSpellStringLowerSplitWithBlank(string str) { string text = ""; for (int i = 0; i < str.Length; i++) { char c = str[i]; if (c >= '!' && c <= '~') { text = text + " " + c.ToString(); } else { text = text + " " + Chinese2Spell.GetSpellCharLower(c.ToString()); } } return(text.Trim()); }
/// <summary> /// 汉字转拼音缩写 (大写) /// </summary> /// <param name="str">要转换的汉字字符串</param> /// <returns>拼音缩写</returns> public static string GetSpellStringSupper(string str) { string text = ""; for (int i = 0; i < str.Length; i++) { char c = str[i]; if (c >= '!' && c <= '~') { //字母和符号原样保留 text += c.ToString(); } else { //累加拼音声母 text += Chinese2Spell.GetSpellCharSupper(c.ToString()); } } return(text); }