1.全拼音

  public static string ToPinyin(this string msg, bool islower=true)
        {
            string result = string.Empty;
            msg= Regex.Replace(msg, @"[^\u4e00-\u9fa5]", string.Empty).Trim();

            foreach (char item in msg)
            {
                var cc = new ChineseChar(item);
                if (cc.Pinyins.Count > 0 && cc.Pinyins[0].Length > 0)
                {
                    string temp = cc.Pinyins[0].ToString();
                    if (islower)
                    {
                        temp = temp.ToLower();
                    }
                    result += temp.Substring(0, temp.Length - 1);
                }
            }
            return result;
        }

2.首字母拼音

   public static string ToFirstPinyin(this string msg, bool islower = true)
        {
            string result = string.Empty;
            msg = Regex.Replace(msg, @"[^\u4e00-\u9fa5]", string.Empty).Trim();
            foreach (var item in msg)
            {
                var cc = new ChineseChar(item);
                if (cc.Pinyins.Count > 0 && cc.Pinyins[0].Length > 0)
                {
                    string temp = cc.Pinyins[0].ToString();
                    if (islower)
                    {
                        temp = temp.ToLower();
                    }
                    result += temp.Substring(0, 1);
                }
            }
            return result;
        }

 

相关文章:

  • 2022-12-23
  • 2021-11-17
  • 2022-01-28
猜你喜欢
  • 2022-12-23
  • 2021-11-10
  • 2021-10-14
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案