Beispiel #1
0
 public static RomanizationConvert GetInstance()
 {
     // 如果类的实例不存在则创建,否则直接返回
     if (pinyinRomanizationConvert == null)
     {
         pinyinRomanizationConvert = new RomanizationConvert();
     }
     return(pinyinRomanizationConvert);
 }
Beispiel #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="hanziStr"></param>
        /// <param name="targetPinyinSystem"></param>
        /// <returns></returns>
        public static string HanyuToRomanizationString(string hanziStr, PinyinRomanizationType targetPinyinSystem)
        {
            var pinyin       = string.Empty;
            var romanization = RomanizationConvert.GetInstance();

            foreach (var hanzi in hanziStr)
            {
                if (!Util.IsHanzi(hanzi))
                {
                    continue;
                }

                var pinyinStrArray = ChineseToPinyinConvert.GetInstance().GetHanyuPinyinStringArray(hanzi);

                if (null != pinyinStrArray)
                {
                    if (pinyinStrArray.Length == 1)
                    {
                        pinyin += romanization.GetRomanizationString(pinyinStrArray[0], PinyinRomanizationType.HANYU_PINYIN, targetPinyinSystem);
                    }
                    else
                    {
                        var arr = new string[] {};
                        for (var i = 0; i < pinyinStrArray.Length; i++)
                        {
                            arr[i] = romanization.GetRomanizationString(pinyinStrArray[i], PinyinRomanizationType.HANYU_PINYIN, targetPinyinSystem);
                        }
                        pinyin += "(" + string.Join(",", arr) + ") ";
                    }
                }
                else
                {
                    return(string.Empty);
                }
            }
            return(pinyin);
        }