DotNet.Utilities/Utilities/StringUtil.PinyinHelper.cs

(开头部分) 37KB

这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。

//-----------------------------------------------------------------
// All Rights Reserved , Copyright (C) 2014 , Hairihan TECH, Ltd. 
//-----------------------------------------------------------------

using System;
using System.Text.RegularExpressions;

namespace DotNet.Utilities
{
    public partial class StringUtil
    {
        #region 获取汉字转换拼音 首字母
        public static string GetPinyinAll(string targetValue)
        //获取汉字字符串的拼音首字母,含多音字
        {
            int i, j, k, m;
            string tmpStr;
            string result = "";  //返回最终结果的字符串
            string[] tmpArr;
            for (i = 0; i < targetValue.Length; i++)
            {   //处理汉字字符串,对每个汉字的首字母进行一次循环
                tmpStr = GetPinyin((char)targetValue[i]);   //获取第i个汉字的拼音首字母,可能为1个或多个
                if (tmpStr.Length > 0)
                {   //汉字的拼音首字母存在的情况才进行操作
                    if (result != "")
                    {   //不是第一个汉字
                        Regex regex = new Regex(",");
                        tmpArr = regex.Split(result);
                        result = "";
                        for (k = 0; k < tmpArr.Length; k++)
                        {
                            for (j = 0; j < tmpStr.Length; j++)    //对返回的每个首字母进行拼接
                            {
                                string charcode = tmpStr[j].ToString(); //取出第j个拼音字母
                                result += tmpArr[k] + charcode + ",";
                            }
                        }
                        if (result != "")
                            result = result.Substring(0, result.Length - 1);
                    }
                    else
                    {   //构造第一个汉字返回结果
                        for (m = 0; m < tmpStr.Length - 1; m++)
                            result += tmpStr[m] + ",";
                        result += tmpStr[tmpStr.Length - 1];
                    }
                }
            }
            return result;   //返回处理结果字符串,以,分隔每个拼音组合
        }

        public static string GetSimpleSpelling(string targetValue)
        {
            string result = string.Empty;
            if (!string.IsNullOrEmpty(targetValue))
            {
                foreach (Char c in targetValue)
                {
                    string pinyin = GetPinyin(c);
                    if (!string.IsNullOrEmpty(pinyin))
后面还有 187 行代码,购买后查看完整代码

24 小时内免费解锁 3 个项目,之后 1 积分/个。 规则说明

AI 解读

登录后可用,每次 10 积分,解读结果公开显示在下面。

还没有人解读过这个文件。