C# 繁体转简体 简体转繁体

时间:2021-12-31 14:35:34

1.下载类库

微软地址:https://www.microsoft.com/zh-cn/download/details.aspx?id=18970 原文地址:http://www.cnblogs.com/xiwang/archive/2012/06/29/2569437.html

下载地址:http://www.microsoft.com/downloads/zh-cn/confirmation.aspx?FamilyID=44cac7f0-633b-477d-aed2-99aee642fc10&DisplayLang=zh-cn(个人建议用这个)

C# 繁体转简体 简体转繁体

2.引用ChineseConverter.dll文件

3.编写代码

using Microsoft.International.Converters.TraditionalChineseToSimplifiedConverter;

        /// <summary> 
        /// 简体转换为繁体
        /// </summary> 
        /// <param name="str">简体字</param> 
        /// <returns>繁体字</returns> 
        public static string GetTraditional(string str)
        {
            string r = string.Empty;
            r = ChineseConverter.Convert(str, ChineseConversionDirection.SimplifiedToTraditional);
            return r;
        }
        /// <summary> 
        /// 繁体转换为简体
        /// </summary> 
        /// <param name="str">繁体字</param> 
        /// <returns>简体字</returns> 
        public static string GetSimplified(string str)
        {
            string r = string.Empty;
            r = ChineseConverter.Convert(str, ChineseConversionDirection.TraditionalToSimplified);
            return r;
        }