Пример #1
0
        /// <summary>
        /// 计算拼音
        /// </summary>
        /// <param name="name"></param>
        /// <param name="counter"></param>
        /// <returns></returns>
        private string CalcPinyin(string name, int counter)
        {
            int    index = 0;
            string code  = string.Empty;

            foreach (var c in name)
            {
                if (index++ == counter)
                {
                    break;
                }
                code += CNToPinyin.GetChineseSpell(c.ToString());
            }
            return(code);
        }
Пример #2
0
        /// <summary>
        /// 按一定步长获取输入中的拼音缩写
        /// </summary>
        /// <param name="name"></param>
        /// <param name="step">步长</param>
        /// <returns></returns>
        private string CalcPinyinStep(string name, int step, int counter)
        {
            string code = string.Empty;

            if (step < name.Length)
            {
                int index = 0;
                for (int i = 0; i < name.Length; i += step)
                {
                    if (index++ < counter)
                    {
                        code += CNToPinyin.GetChineseSpell(name[i].ToString());
                    }
                }
            }
            else//所有名称小于步长,则显示所有名称的首个拼音
            {
                foreach (var c in name)
                {
                    code += CNToPinyin.GetChineseSpell(c.ToString());
                }
            }
            return(code);
        }