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 (包含链接)
  • 相关阅读:
    Android · SQLite
    Android · 获取网络图片
    Android · 广告走灯
    Android · 动画
    Android常用资源
    Android · Fragment
    JSP 自动刷新
    JSP 点击量统计
    JSP 页面重定向
    JSP 日期处理
  • 原文地址:https://www.cnblogs.com/gaobing/p/14485368.html
Copyright © 2011-2022 走看看