• C# 汉字转拼音(全拼)


    汉字转拼音(全拼)
        /// <summary>
        
    /// 汉字转拼音类
        
    /// </summary>

        public class Hz2Py
        
    {
            
    定义拼音字符串

            
    /// <summary>
            
    /// 把汉字转换成拼音(全拼)
            
    /// </summary>
            
    /// <param name="hzString">汉字字符串</param>
            
    /// <returns>转换后的拼音(全拼)字符串</returns>

            public static string Convert(string hzString)
            
    {
                Regex regex 
    = new Regex("^[\u4e00-\u9fa5]$");
                
    byte[] array = new byte[2];
                
    string pyString = "";
                
    int chrAsc = 0;
                
    int i1 = 0;
                
    int i2 = 0;
                
    char[] noWChar = hzString.ToCharArray();

                
    for (int j = 0; j < noWChar.Length; j++)
                
    {
                    
    if (regex.IsMatch(noWChar[j].ToString()))
                    
    {
                        array 
    = System.Text.Encoding.Default.GetBytes(noWChar[j].ToString());
                        i1 
    = (short)(array[0]);
                        i2 
    = (short)(array[1]);
                        chrAsc 
    = i1 * 256 + i2 - 65536;
                        
    if (chrAsc > 0 && chrAsc < 160)
                        
    {
                            pyString 
    += noWChar[j];
                        }

                        
    else
                        
    {
                            
    // 修正部分文字
                            if (chrAsc == -9254)  // 修正“圳”字
                                pyString += "Zhen";
                            
    else
                            
    {
                                
    for (int i = (pyValue.Length - 1); i >= 0; i--)
                                
    {
                                    
    if (pyValue[i] <= chrAsc)
                                    
    {
                                        pyString 
    += pyName[i];
                                        
    break;
                                    }

                                }

                            }

                        }

                    }

                    
    else
                    
    {
                        pyString 
    += noWChar[j].ToString();
                    }

                }

                
    return pyString;
            }

        }
  • 相关阅读:
    敏捷个人2013.06月份户外活动报道:奥森健步读书分享会
    敏友的【敏捷个人】有感(16): 成为一个敏捷的人
    #敏捷个人# 每日认识101(14):成为一个敏捷个人
    4周的敏捷生活练习,你来吗?
    OKGo vs RxHttpUtils ...
    Android开发之EditText多行文本输入
    android开发中json与java对象相互转换
    android 调试崩溃Unable to instantiate application的解决方法
    Android.mk 使用说明
    几种知名开源富文本编辑器记录和对比(仅供参考)
  • 原文地址:https://www.cnblogs.com/smallfa/p/911488.html
Copyright © 2020-2023  润新知