Esempio n. 1
0
        /// <summary>
        /// 获得拼音字符串
        /// </summary>
        /// <param name="split">每个拼音之间的分隔符</param>
        /// <param name="buildType">组装拼音字符串的方式</param>
        /// <returns></returns>
        public string GetPinYinString(string split, BuildType buildType)
        {
            var sb = new StringBuilder();
            IList<string> list = null;
            if (PinYin != null)
            {
                list = new List<string>(PinYin);
            }

            if (list == null || list.Count == 0)
            {
                var pyGenerater = new PinyinGenerater();
                list = pyGenerater.GetCodeOfString(word);
            }
            if (list.Count == 0)
            {
                return "";
            }
            foreach (string s in list)
            {
                sb.Append(s + split);
            }
            if (buildType == BuildType.RightContain)
            {
                return sb.ToString();
            }
            if (buildType == BuildType.FullContain)
            {
                return split + sb;
            }
            string str = sb.ToString();
            if (split.Length > 0)
            {
                str = str.Remove(sb.Length - 1);
            }
            if (buildType == BuildType.None)
            {
                return str;
            }
            else //BuildType.LeftContain
            {
                return split + str;
            }
        }