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
    评论
C#中使用OpcComRcw.dll,需要进行以下步骤: 1. 添加对OpcComRcw.dll的引用。在Visual Studio中,打开项目,右键单击“引用”文件夹,选择“添加引用”,在“COM”选项卡中找到并选择OpcComRcw.dll。 2. 在代码文件中添加命名空间引用。在代码文件的顶部添加以下命名空间引用: using OpcRcw.Da; using OpcRcw.Comn; 3. 创建并配置OPC服务器连接。使用以下代码创建并配置OPC服务器连接: private static IOPCServer opcServer; private static IOPCBrowseServerAddressSpace browser; Guid iid = typeof(IOPCServer).GUID; Type type = Type.GetTypeFromCLSID(iid); opcServer = (IOPCServer)Activator.CreateInstance(type); iid = typeof(IOPCBrowseServerAddressSpace).GUID; type = Type.GetTypeFromCLSID(iid); browser = (IOPCBrowseServerAddressSpace)Activator.CreateInstance(type); browser.Connect("localhost"); 4. 浏览和选择OPC项。使用以下代码浏览和选择OPC项: OPCITEMDEF[] itemDefs = new OPCITEMDEF[1]; itemDefs[0] = new OPCITEMDEF(); itemDefs[0].szAccessPath = ""; itemDefs[0].szItemID = "Random.Int1"; itemDefs[0].bActive = 1; itemDefs[0].hClient = 1; OPCITEMRESULT[] itemResults; opcServer.AddItems(1, itemDefs, out itemResults); 5. 读取和写入OPC项的值。使用以下代码读取和写入OPC项的值: OPCITEMSTATE[] itemStates; opcServer.Read(OPCDATASOURCE.OPC_DS_DEVICE, 1, itemResults[0].hServer, out itemStates); object value = 12345; opcServer.Write(1, new int[] { itemResults[0].hServer }, new object[] { value }, out errors); 以上是使用C# OpcComRcw.dll进行OPC通信的基本步骤。可以根据具体需求进行更多的操作和定制。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值