WYB
2021-03-22 91b8cdad021ab052e4991f3d41834a6f0ddc36b8
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
using System;
using NPinyin;
using System.Text;
 
namespace JiepeiWMS.Common.Helper
{
    public class PinYinHelper
    {
        /// <summary>
        /// 汉字转小写全拼
        /// </summary>
        /// <param name="strChinese"></param>
        /// <returns></returns>
        public static string ConvertToAllSpell(string strChinese)
        {
            try
            {
                if (strChinese.Length != 0)
                {
                    StringBuilder fullSpell = new StringBuilder();
                    for (int i = 0; i < strChinese.Length; i++)
                    {
                        var chr = strChinese[i];
                        fullSpell.Append(GetSpell(chr));
                    }
                    return fullSpell.ToString().ToLower();//转小写方法为 .ToLower()
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("出错!" + e.Message);
            }
            return string.Empty;
        }
 
        private static string GetSpell(char chr)
        {
            var coverchr = Pinyin.GetPinyin(chr);
            return coverchr;
        }
    }
}