C#中文转换成拼音英文

#region 0.1 中文转到英文 + static string GetPinYing(string characters)
        /// 
        /// 中文转到英文
        /// 
        /// 
        /// 
        public static string GetPinYing(string characters)
        {
            if (characters.Length != 0)
            {
                StringBuilder fullSpellBuild = new StringBuilder();
                for (int i = 0; i < characters.Length; i++)
                {
                    //判断是否是中文
                    bool itemFlag = ChineseChar.IsValidChar(characters[i]);
                    if (itemFlag)
                    {
                        ChineseChar chineseChar = new ChineseChar(characters[i]);
                        foreach (string value in chineseChar.Pinyins)
                        {
                            if (!string.IsNullOrEmpty(value))
                            {
                                fullSpellBuild.Append(value.Remove(value.Length - 1, 1));
                                break;
                            }
                        }
                    }
                    else
                    {
                        fullSpellBuild.Append(characters[i]);
                    }
                }
                return fullSpellBuild.ToString();
            }
            return "";
        }
        #endregion

需要添加ChnCharInfo.DLL

转载于:https://www.cnblogs.com/iack/p/3539128.html

你可能感兴趣的:(c#)