private static string[] GetFomattedHanyuPinyinStringArray( char ch, HanyuPinyinOutputFormat format) { string[] unformattedArr = GetUnformattedHanyuPinyinStringArray(ch); if (null != unformattedArr) { for (int i = 0; i < unformattedArr.Length; i++) { unformattedArr[i] = PinyinFormatter.FormatHanyuPinyin(unformattedArr[i], format); } } return(unformattedArr); }
/// <summary> /// 获取格式化后的拼音 /// </summary> /// <param name="hanzi">要查询拼音的汉字字符</param> /// <param name="format">拼音输出格式化参数</param> /// <see cref="PinyinOutputFormat"/> /// <seealso cref="PinyinFormatter"/> /// <returns>经过格式化的拼音</returns> /// <exception cref="UnsupportedUnicodeException">当要获取拼音的字符不是汉字时抛出此异常</exception> public static string[] GetPinyinWithFormat(char hanzi, PinyinOutputFormat format) { return(GetPinyin(hanzi).Select(item => PinyinFormatter.Format(item, format)).ToArray()); }
/// <summary> /// 获取格式化后的唯一拼音(单音字)或者第一个拼音(多音字) /// </summary> /// <param name="hanzi">要查询拼音的汉字字符</param> /// <param name="format">拼音输出格式化参数</param> /// <see cref="PinyinOutputFormat"/> /// <seealso cref="PinyinFormatter"/> /// <returns>格式化后的唯一拼音(单音字)或者第一个拼音(多音字)</returns> /// <exception cref="UnsupportedUnicodeException">当要获取拼音的字符不是汉字时抛出此异常</exception> public static string GetUniqueOrFirstPinyinWithFormat(char hanzi, PinyinOutputFormat format) { return(PinyinFormatter.Format(GetUniqueOrFirstPinyin(hanzi), format)); }
/// <summary> /// 获取格式化后的拼音 /// </summary> /// <param name="firstName">要查询拼音的姓</param> /// <param name="format">输出拼音格式化参数</param> /// <see cref="PinyinOutputFormat"/> /// <seealso cref="PinyinFormatter"/> /// <returns>返回格式化后的拼音,若未找到姓,则返回null</returns> /// <exception cref="UnsupportedUnicodeException">当要获取拼音的字符不是汉字时抛出此异常</exception> public static string GetPinyinWithFormat(string firstName, PinyinOutputFormat format) { return(string.Join(" ", GetPinyin(firstName).Split(' ').Select(item => PinyinFormatter.Format(item, format)))); }