zoukankan      html  css  js  c++  java
  • .net core 使用PinYinConverterCore 汉字转拼音

    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;
            }
    作者: jamesbing
    提示: 欢迎转载,但是必须保留本文的署名 jamesbing (包含链接)
  • 相关阅读:
    react 入坑笔记(五)
    练习
    高级指令
    进阶指令
    基础指令
    VMware 备份操作系统
    Ubuntu 用户的切换
    形态学转换
    图像模糊
    域名拆分 tld
  • 原文地址:https://www.cnblogs.com/gaobing/p/14485368.html
Copyright © 2011-2022 走看看