国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > C# > 正文

C# 漢字轉(zhuǎn)化拼音的簡單實例代碼

2020-01-24 03:27:52
字體:
供稿:網(wǎng)友

首先引入ChnCharInfo.dll 第3方的一個庫

代碼:

btn_chinChar_Click事件:

復(fù)制代碼 代碼如下:

private void btn_chinChar_Click(object sender, EventArgs e)
        {
            ChineseChar cr =null;
            string str = "", txtString = txt_string.Text.Trim();
            if (!string.IsNullOrEmpty(txtString))
            {
                foreach (var item in cr.GetChineseSpellings(txtString))
                {
                    str += item + "-";
                }
            }
            MessageBox.Show(str);
        }

擴展方法:

復(fù)制代碼 代碼如下:

public static class ChineseCharacters
    {
        public static ICollection<string> GetChineseSpellings(this ChineseChar chinChar ,string value)
        {
            List<string> list;
            int i,start;
            char c;

            if (string.IsNullOrEmpty(value))return null;

            start = 0;
            list = new List<string>();

            for (i = 0; i < value.Length; ++i)
            {
                c = value[i];
                if (ChineseChar.IsValidChar(c))
                {
                    if (i > start)
                    {
                        list.Add(value.Substring(start, i - start));
                    }
                    chinChar = new ChineseChar(c);
                    list.Add(chinChar.Pinyins.First().Substring(0, chinChar.Pinyins.First().Length - 1).ToLower());
                    start = i + 1;
                }
            }

            if (i > start)
            {
                list.Add(value.Substring(start, i - start));
            }
            return list;
        }
    }


運用結(jié)果:

發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 灵寿县| 濉溪县| 项城市| 伊川县| 迭部县| 杨浦区| 南皮县| 镇安县| 北流市| 内丘县| 岱山县| 马公市| 钦州市| 天门市| 杨浦区| 塘沽区| 枞阳县| 永靖县| 五指山市| 共和县| 永登县| 铁岭市| 离岛区| 重庆市| 柳江县| 陇西县| 南靖县| 东港市| 邛崃市| 深州市| 万安县| 德庆县| 衡阳县| 富顺县| 济源市| 高淳县| 湛江市| 阳信县| 定边县| 平阴县| 文成县|