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();
}
}
}
using ChineseSpell;
ChineseSpell.DLL 的下载地址:
调用例子下载地址:
若有问题,欢迎吐槽
新手一枚,望大家多给些意见与见解