Beispiel #1
0
 public static GwoyeuRomatzyhConvert GetInstance()
 {
     // 如果类的实例不存在则创建,否则直接返回
     if (gwoyeuRomatzyhConvert == null)
     {
         gwoyeuRomatzyhConvert = new GwoyeuRomatzyhConvert();
     }
     return(gwoyeuRomatzyhConvert);
 }
Beispiel #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="hanziStr"></param>
        /// <returns></returns>
        public static string HanyuToGwoyeuRomatzyhString(string hanziStr)
        {
            var pinyin       = string.Empty;
            var romanization = GwoyeuRomatzyhConvert.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.GetGwoyeuRomatzyh(pinyinStrArray[0]) + " ";
                    }
                    else
                    {
                        var arr = new string[] { };
                        for (var i = 0; i < pinyinStrArray.Length; i++)
                        {
                            arr[i] = romanization.GetGwoyeuRomatzyh(pinyinStrArray[i]);
                        }
                        pinyin += "(" + string.Join(",", arr) + ") ";
                    }
                }
                else
                {
                    return(string.Empty);
                }
            }
            return(pinyin);
        }