zoukankan      html  css  js  c++  java
  • 汉字提取拼音首字母修正

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;

    namespace GetCNSpell
    {
        public class GetCNSpell
        {
            /// <summary>  
            /// 提取汉字首字母  
            /// </summary> 施彪 
            /// <param name="strText">需要转换的字</param>  
            /// <returns>转换结果</returns>  
            public string GetChineseSpell(string strText)
            {
                int len = strText.Length;
                string myStr = "";
                for (int i = 0; i < len; i++)
                {
                    myStr += getSpell(strText.Substring(i, 1));
                }
                return myStr;
            }
            /// <summary>  
            /// 把提取的字母变成小写  
            /// </summary>  
            /// <param name="strText">需要转换的字符串</param>  
            /// <returns>转换结果</returns>  
            public string GetLowerChineseSpell(string strText)
            {
                return GetChineseSpell(strText).ToLower();
            }
            /// <summary>  
            /// 把提取的字母变成大写  
            /// </summary>  
            /// <param name="myChar">需要转换的字符串</param>  
            /// <returns>转换结果</returns>  
            public string GetUpperChineseSpell(string strText)
            {
                return GetChineseSpell(strText).ToUpper();
            }
            /// <summary>  
            /// 获取单个汉字的首拼音  
            /// </summary>  
            /// <param name="myChar">需要转换的字符</param>  
            /// <returns>转换结果</returns>  
            public string getSpell(string str)
            {
                if (str.CompareTo("吖") < 0)
                {
                    string s = str.Substring(0, 1);
                    if (char.IsNumber(s, 0))
                    {
                        return s;
                    }
                    else
                    {
                        return s;
                    }
                }
                else if (str.CompareTo("八") < 0)
                {
                    return "A";
                }
                else if (str.CompareTo("嚓") < 0)
                {
                    return "B";
                }
                else if (str.CompareTo("咑") < 0)
                {
                    return "C";
                }
                else if (str.CompareTo("妸") < 0)
                {
                    return "D";
                }
                else if (str.CompareTo("发") < 0)
                {
                    return "E";
                }
                else if (str.CompareTo("旮") < 0)
                {
                    return "F";
                }
                else if (str.CompareTo("铪") < 0)
                {
                    return "G";
                }
                else if (str.CompareTo("讥") < 0)
                {
                    return "H";
                }
                else if (str.CompareTo("咔") < 0)
                {
                    return "J";
                }
                else if (str.CompareTo("垃") < 0)
                {
                    return "K";
                }
                else if (str.CompareTo("嘸") < 0)
                {
                    return "L";
                }
                else if (str.CompareTo("拏") < 0)
                {
                    return "M";
                }
                else if (str.CompareTo("噢") < 0)
                {
                    return "N";
                }
                else if (str.CompareTo("妑") < 0)
                {
                    return "O";
                }
                else if (str.CompareTo("七") < 0)
                {
                    return "P";
                }
                else if (str.CompareTo("亽") < 0)
                {
                    return "Q";
                }
                else if (str.CompareTo("仨") < 0)
                {
                    return "R";
                }
                else if (str.CompareTo("他") < 0)
                {
                    return "S";
                }
                else if (str.CompareTo("哇") < 0)
                {
                    return "T";
                }
                else if (str.CompareTo("夕") < 0)
                {
                    return "W";
                }
                else if (str.CompareTo("丫") < 0)
                {
                    return "X";
                }
                else if (str.CompareTo("帀") < 0)
                {
                    return "Y";
                }
                else if (str.CompareTo("咗") < 0)
                {
                    return "Z";
                }
                else
                {
                    return str;
                }
            }

        }
    }

  • 相关阅读:
    一个接口的性能问题定位和分析过程
    HTTP请求全过程(很全面)
    Linux中查看物理CPU个数、核数、逻辑CPU个数
    linux查看文件大小
    ping不通判断系统是否开机
    ping不通判断系统是否开机
    linux压缩解压文件命令
    python连接redis集群,添加数据
    初学python
    企业级BI为什么这么难做?
  • 原文地址:https://www.cnblogs.com/yuerdongni/p/2651402.html
Copyright © 2011-2022 走看看