コード例 #1
0
        /// <summary>
        /// 获取单个字符的拼音,单个字符为多音字时,返回第一个拼音
        /// </summary>
        /// <param name="word">待转换的字符</param>
        /// <param name="pinyinTone">设置以何种方式返回拼音的声调</param>
        /// <returns></returns>
        public string GetSingleFirstPinyin(char word, PinyinTone pinyinTone)
        {
            string pinyin = FindPinyin(word);

            string[] pinyins = pinyin.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
            pinyin = pinyins[0];
            if (pinyin.Length > 1)
            {
                pinyin = SetPinyinTone(pinyins[0], pinyinTone);
            }
            return(pinyin);
        }
コード例 #2
0
        /// <summary>
        /// 获取单个字符的拼音,单个字符为多音字时,返回所有的拼音
        /// </summary>
        /// <param name="word">待转换的字符</param>
        /// <param name="pinyinTone">设置以何种方式返回拼音的声调</param>
        /// <returns></returns>
        public string[] GetSingleFullPinyin(char word, PinyinTone pinyinTone)
        {
            string pinyin = FindPinyin(word);

            string[] pinyins = pinyin.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
            for (int i = 0; i < pinyins.Length; i++)
            {
                pinyin = pinyins[i];
                if (pinyin.Length > 1)
                {
                    pinyins[i] = SetPinyinTone(pinyins[i], pinyinTone);
                }
            }
            return(pinyins);
        }
コード例 #3
0
        private string SetPinyinTone(string pinyin, PinyinTone pinyinTone)
        {
            switch (pinyinTone)
            {
            case PinyinTone.None:
                pinyin = pinyin.Remove(pinyin.Length - 1, 1);
                break;

            case PinyinTone.Numeral:
                break;

            case PinyinTone.Alphabetic:
                pinyin = PinyinAlphabeticTone.GetAlpTone(pinyin);
                break;
            }
            return(pinyin);
        }
コード例 #4
0
 /// <summary>
 /// 获取整个字符串的拼音,当某个字符为多音字时,使用其上下文匹配多音字
 /// </summary>
 /// <param name="text">待转换的字符串</param>
 /// <param name="pinyinTone">设置以何种方式返回拼音的声调</param>
 /// <param name="separator">设置以何种字符串分割每个字符的拼音</param>
 /// <returns></returns>
 public string GetFullPinyin(string text, PinyinTone pinyinTone, string separator)
 {
     if (!string.IsNullOrEmpty(text))
     {
         string pinyin;
         string result = string.Empty;
         for (int i = 0; i < text.Length; i++)
         {
             pinyin = FindMultPinyin(text, i);
             if (pinyin.Length > 1)
             {
                 pinyin  = SetPinyinTone(pinyin, pinyinTone);
                 result += pinyin + separator;
             }
             else
             {
                 result += pinyin;
             }
         }
         return(result);
     }
     return(string.Empty);
 }
コード例 #5
0
 /// <summary>
 /// 获取整个字符串的拼音,当某个字符为多音字时,使用其上下文匹配多音字
 /// </summary>
 /// <param name="text">待转换的字符串</param>
 /// <param name="pinyinTone">设置以何种方式返回拼音的声调</param>
 /// <returns></returns>
 public string GetFullPinyin(string text, PinyinTone pinyinTone)
 {
     return(GetFullPinyin(text, pinyinTone, ""));
 }