C# ChineseSpell.DLL 简体汉字转拼音

ChineseSpell.DLL

主要函数调用:

using System;
using System.Collections.Generic;
using System.Runtime.CompilerServices;

namespace ChineseSpell
{
    // 摘要: 
    //     汉字转拼音辅助类
    public static class ChineseSpellHelper
    {
        // 摘要: 
        //     获取拼音首字母与全拼组合(不带音标) Key:拼音首字母,Value:以该首字母开头的拼音组合
        //
        // 参数: 
        //   source:
        public static Dictionary<string, string[]> GetAllSpellWithoutTone(this string source);
        //
        // 摘要: 
        //     获取拼音字母与全拼以及全拼带字母的所有组合 Key1:拼音首字母,Value1:{Key2:拼音,Value2:所有读音组合}
        //
        // 参数: 
        //   source:
        public static Dictionary<string, Dictionary<string, string[]>> GetAllSpellWithTone(this string source);
        //
        // 摘要: 
        //     获取拼音,不带音调
        //
        // 参数: 
        //   source:
        public static string[] GetFullSpellWithoutTone(this string source);
        //
        // 摘要: 
        //     获取带声调的拼音 每个拼音间以空格分隔
        //
        // 参数: 
        //   source:
        public static string[] GetFullSpellWithTone(this string source);
        //
        // 摘要: 
        //     获取拼音首字母
        //
        // 参数: 
        //   source:
        public static string[] GetSortSpell(this string source);
        //
        // 摘要: 
        //     获取不带音调的拼音模型集合
        //
        // 参数: 
        //   source:
        public static List<ShortSpellModel> GetSpellModelWithoutTone(this string source);
        //
        // 摘要: 
        //     获取带音调的拼音模型集合
        //
        // 参数: 
        //   source:
        public static List<ShortSpellModel> GetSpellModelWithTone(this string source);
        //
        // 摘要: 
        //     获取拼音,不带音调
        //
        // 参数: 
        //   source:
        public static string[] GetWordFullSpellWithoutTone(this char source);
        //
        // 摘要: 
        //     获取带声调的拼音
        //
        // 参数: 
        //   source:
        public static string[] GetWordFullSpellWithTone(this char source);
        //
        // 摘要: 
        //     获取拼音首字母
        //
        // 参数: 
        //   source:
        public static string[] GetWordSortSpell(this char source);
        //
        // 摘要: 
        //     判断字符是否是汉字
        //
        // 参数: 
        //   source:
        public static bool IsChinese(this char source);
    }
}

涉及的实体类:

using System;
using System.Collections.Generic;

namespace ChineseSpell
{
    // 摘要: 
    //     拼音首字母实体类
    public class ShortSpellModel
    {
        public ShortSpellModel();

        // 摘要: 
        //     全拼集合
        public List<FullSpellModel> FullSpells { get; set; }
        //
        // 摘要: 
        //     首字母拼音
        public string ShortSpell { get; set; }
    }
}

using System;
using System.Collections.Generic;

namespace ChineseSpell
{
    // 摘要: 
    //     全拼实体类
    public class FullSpellModel
    {
        public FullSpellModel();

        // 摘要: 
        //     全拼拼音
        public string FullSpellWithoutTone { get; set; }
        //
        // 摘要: 
        //     带音标的全拼集合
        public List<FullToneSpellModel> FullSpellWithTone { get; set; }
        //
        // 摘要: 
        //     首字母拼音
        public string ShortSpell { get; set; }
    }
}

using System;

namespace ChineseSpell
{
    // 摘要: 
    //     带音标的全拼实体类
    public class FullToneSpellModel
    {
        public FullToneSpellModel();

        // 摘要: 
        //     全拼拼音
        public string FullSpellWithoutTone { get; set; }
        //
        // 摘要: 
        //     带音标的全拼
        public string FullSpellWithTone { get; set; }
        //
        // 摘要: 
        //     首字母拼音
        public string ShortSpell { get; set; }
    }
}

调用方式:

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

namespace ChineseSpellTestConsoleApplication
{
    class Program
    {
        static void Main(string[] args)
        {
            #region 字符串调用


            string word = "家区厂";

            //获取拼音首字母与全拼的排列组合,不带音标
            var result1 = word.GetAllSpellWithoutTone();

            //获取拼音首字母与全拼的排列组合,带音标
            var result2 = word.GetAllSpellWithTone();

            //获取全拼的排列组合,不带音标
            var result3 = word.GetFullSpellWithoutTone();

            //获取全拼的排列组合,带音标
            var result4 = word.GetFullSpellWithTone();

            //获取首字母排列组合
            var result5 = word.GetSortSpell();

            //获取拼音实体类结果集合,不带音标
            var result6 = word.GetSpellModelWithoutTone();

            //获取拼音实体类结果集合,带音标
            var result7 = word.GetSpellModelWithTone();
            
            #endregion

            #region 字符调用


            char word2 = '家';

            //判断字符是否是汉字
            var result8 = word2.IsChinese();

            //获取字符的全拼组合,不带音标
            var result9 = word2.GetWordFullSpellWithoutTone();
            
            //获取字符的全拼组合,带音标
            var result10 = word2.GetWordFullSpellWithTone();

            //获取字符的拼音首字母组合
            var result11 = word2.GetWordSortSpell();
            
            #endregion

            Console.ReadLine();
        }
    }
}


使用前记得引用命名空间 ChineseSpell;

using ChineseSpell;

ChineseSpell.DLL 的下载地址:

【ChineseSpell.DLL 】


调用例子下载地址:

【调用例子】


若有问题,欢迎吐槽

新手一枚,望大家多给些意见与见解

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值