dotnet中文字符工具类
支持繁体简体互换。
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Threading.Tasks; namespace DLMApi.Utils
{
/// <summary>
/// 中文字符工具类
/// </summary>
public class ChineseStringUtility
{
private const int LOCALE_SYSTEM_DEFAULT = 0x0800;
private const int LCMAP_SIMPLIFIED_CHINESE = 0x02000000;
private const int LCMAP_TRADITIONAL_CHINESE = 0x04000000; [DllImport("kernel32", CharSet = CharSet.Auto, SetLastError = true)]
private static extern int LCMapString(int Locale, int dwMapFlags, string lpSrcStr, int cchSrc, [Out] string lpDestStr, int cchDest); /// <summary>
/// 将字符转换成简体中文
/// </summary>
/// <param name="source">输入要转换的字符串</param>
/// <returns>转换完成后的字符串</returns>
public static string ToSimplified(string source)
{
String target = new String(' ', source.Length);
int ret = LCMapString(LOCALE_SYSTEM_DEFAULT, LCMAP_SIMPLIFIED_CHINESE, source, source.Length, target, source.Length);
return target;
} /// <summary>
/// 将字符转换为繁体中文
/// </summary>
/// <param name="source">输入要转换的字符串</param>
/// <returns>转换完成后的字符串</returns>
public static string ToTraditional(string source)
{
String target = new String(' ', source.Length);
int ret = LCMapString(LOCALE_SYSTEM_DEFAULT, LCMAP_TRADITIONAL_CHINESE, source, source.Length, target, source.Length);
return target;
} // <summary>
/// 获取两个字符串的相似度
/// </summary>
/// <param name=”sourceString”>第一个字符串</param>
/// <param name=”str”>第二个字符串</param>
public static int GetSimilarityWith(string sourceString, string str)
{
char[] ss = sourceString.ToCharArray();
char[] st = str.ToCharArray(); //获取交集数量
int q = ss.Intersect(st).Count();
return q;
} }
}
dotnet中文字符工具类的更多相关文章
- Java原生隐藏字符-工具类
package com.seesun2012.common.util; /** 隐藏字符-工具类 @author seesun2012@163.com */ public class HiddenCh ...
- .net使用正则表达式校验、匹配字符工具类
开发程序离不开数据的校验,这里整理了一些数据的校验.匹配的方法: /// <summary> /// 字符(串)验证.匹配工具类 /// </summary> public c ...
- 有意思的String字符工具类
对String的操作是Java攻城师必备的,一个优秀的攻城师是懒惰,他会把自己的一些常见的代码写成可提供拓展和复用的工具类或者工具库,这些是这些优秀工程师的法宝. 我就先从String这个基本操作开始 ...
- libgdx游戏中的中文字体工具类
// ---------全局Font------------ static FreeTypeFontGenerator Generator; static BitmapFont Font; stati ...
- Java_常用工具类收集
一.日期工具类 package com.ebd.application.common.utils; import java.sql.Timestamp; import java.text.DateFo ...
- C++ 简单中文敏感词检测工具类
具体思路: 1->敏感词库,可从数据库读取,也可以从文件加载. 2->将敏感词转化为gbk编码,因为gbk严格按照字符一个字节,汉字两个字节的格式编码,便于容易切分文字段. 3->将 ...
- 【转载】C#工具类:人民币金额转换为中文大写
在涉及到金融业务这一块的系统设计中,时常能够遇到的情况是需要将阿拉伯数字的人民币金额自动转换为中文的大写金额.现在互联网上也有很多网站提供此类服务,只要你输入人民币的阿拉伯数字金额,输入后自动给你转换 ...
- Java读取properties文件工具类并解决控制台中文乱码
1.建立properts文件(error.message.properties) HTTP201= 请求成功并且服务器创建了新的资源 2.在spring-mvc.xml文件(applicationCo ...
- PHP 中文工具类,支持汉字转拼音、拼音分词、简繁互转
ChineseUtil 下载地址:https://github.com/Yurunsoft/ChineseUtil 另外一个中文转拼音工具:https://github.com/overtrue/pi ...
随机推荐
- JMETER 审批任务实战
业务场景 我们需要对流程任务进行审批,这个和流程发起是不一样的,因为在流程发起时,只需要用户登录后,指定固定的流程方案和数据就可以发起流程了. 流程任务是需要获取任务ID再做任务审批的. 实现思路 1 ...
- linux命令提示符解析
linux命令提示符 命令窗口中[root@chengfeng ~]# 表示什么意思? root 当前登录终端的用户 chengfeng 主机名(/etc/ ...
- Bert实战---情感分类
1.情感分析语料预处理 使用酒店评论语料,正面评论和负面评论各5000条,用BERT参数这么大的模型, 训练会产生严重过拟合,,泛化能力差的情况, 这也是我们下面需要解决的问题; 2.sigmoid二 ...
- 201871010125 王玉江 《面向对象程序设计(java)》 第四周学习总结
项目 内容 这个作业属于哪个课程 https://www.cnblogs.com/nwnu-daizh/ 这个作业的要求在哪里 https://www.cnblogs.com/wswyj/ 作业学习目 ...
- thymeleaf关于js的一些坑
乍一看,没问题,也许对应用过thymeleaf的小伙伴来说一眼就看出了问题,但是对于新手确实很难发现,thymeleaf会把[[]]中的内容作为内联取值块解析,而不是数组. 解决办法 方法一: < ...
- 【oracle】 months_between(date1,date2)
(20090228,20080228)====12 (20090228,20080229)====12 (20080229,20070228)====12 (20100331,20100228)=== ...
- Java System.getProperty vs System.getenv
转自:https://www.baeldung.com/java-system-get-property-vs-system-getenv 1. Introduction The package ja ...
- Linux学习笔记-第2天- 新的开始
迟到且稀疏的笔记,希望自己今年会有所突破.加油
- java ++和--
public class Sample { public static void main(String[] args) { , num2 = ; , num4 = ; System.out.prin ...
- mongodb 系列 ~ mongo 用户验证系列
MongoClientURI connectionString = new MongoClientURI("mongodb://root:****@dds-bp114e3f1fc441342 ...