C#   文件简繁体转换

简繁体转换:

方案一:

准确性高,耗性能

方案二:

准确性低,效率高

 1 using Microsoft.International.Converters.TraditionalChineseToSimplifiedConverter;
2 using System;
3 using System.Collections.Generic;
4 using System.IO;
5 using System.Linq;
6 using System.Text;
7 using System.Text.RegularExpressions;
8
9 namespace Simplified_Demo
10 {
11 class Program
12 {
13 static void Main(string[] args)
14 {
15 Regex regHtml = new Regex(@"[\u4e00-\u9fbb]+");
16
17 var directoryStr = System.Configuration.ConfigurationManager.AppSettings["DirectoryStr"];
18 var encodingStr = System.Configuration.ConfigurationManager.AppSettings["EncodingStr"];
19 var filesPath = Directory.GetFiles(directoryStr, "*.*", SearchOption.AllDirectories);
20 int count = 0;
21 string strContent = string.Empty;
22 foreach (var filePath in filesPath)
23 {
24 //js,html,htm,aspx,
25 var ext = Path.GetExtension(filePath).ToLower();
26
27 if (ext.EndsWith("js") || ext.EndsWith("html") || ext.EndsWith("htm") || ext.EndsWith("aspx") || ext.EndsWith("xml"))
28 {
29 if (File.Exists(filePath))
30 {
31 try
32 {
33 if (string.IsNullOrEmpty(encodingStr))
34 {
35 strContent = File.ReadAllText(filePath);
36 }
37 else
38 {
39 strContent = File.ReadAllText(filePath, Encoding.UTF8);
40 }
41
42 var matchs = regHtml.Matches(strContent);
43 if (matchs.Count == 0) continue;
44
45 foreach (Match m in matchs)
46 {
47 var txt = ChineseConverter.Convert(m.ToString(), ChineseConversionDirection.SimplifiedToTraditional);
48 strContent = Regex.Replace(strContent, m.ToString(), txt);
49 }
50 }
51 catch (Exception)
52 {
53 }
54 if (string.IsNullOrEmpty(encodingStr))
55 {
56 File.WriteAllText(filePath, strContent);
57 }
58 else
59 {
60 File.WriteAllText(filePath, strContent, Encoding.UTF8);
61 }
62 }
63
64 Console.WriteLine(filesPath.Length);
65 Console.Write("|" + count++);
66 }
67 }
68 Console.WriteLine("OK");
69 Console.ReadKey();
70 }
71 }
72 }

c# 文件简繁体转换的更多相关文章

  1. 我的Android进阶之旅------>Android中如何高效率的进行简繁体转换

    因为APP要做国际化适配,所以就需要顾及到香港和台湾都是使用繁体字,怎样快速便捷高效的把简体字转换成繁体字呢? 说实话我之前用的方法比较呆板,把每个需要转换的字符串进行在线翻译.今天突然发现word或 ...

  2. Python实现简繁体转换,真的玩得花

    大家好鸭, 我是小熊猫 直接开搞!!! 1.opencc-python 首先介绍opencc中的Python实现库,它具有安装简单,翻译准确,使用方便等优点.对于我们日常的需求完全能够胜任. 1.1安 ...

  3. asp.net简繁体转换

    简繁体转换添加Microsoft.VisualBasic.dll引用 //简转繁 string str= Microsoft.VisualBasic.Strings.StrConv("民生银 ...

  4. Delphi汉字简繁体转换代码(分为D7和D2010版本)

    //delphi 7 Delphi汉字简繁体转换代码unit ChineseCharactersConvert; interface uses   Classes, Windows; type   T ...

  5. 利用js轻松实现页面简繁体转换

    使用方法:StranBody(); //转换对象,使用递归,逐层剥到文本 function StranBody(fobj) { if(typeof(fobj)=="object") ...

  6. C#简繁体转换

    /// <summary>/// 字符串简体转繁体/// </summary>/// <param name="strSimple"></ ...

  7. js搞定网页的简繁转换

    对网页进行简繁字体转换的方法一般有两种:一是使用<简繁通>这样的专业软件,另外一种是制作两套版本的网页.显然,这两种方法都较为麻烦,而且专业软件一般不能用于免费的空间.笔者在这里给大家提供 ...

  8. 简繁体互换工具:opencc

    简繁体互换工具:opencc opencc是一个简体.繁体相互转换的命令行工具. 安装 下载软件包.在下载页面下载软件包(如1.0.4版本) 解压.通过命令解压:tar -xzvf opencc-1. ...

  9. js如何实现简繁体互转

    js如何实现简繁体互转 一.总结 一句话总结:其实无论是简体还是繁体,都是在显示端(前端),其实所有的我只用动js就好了,没必要动php. 当然,后端也可以做前端的事情,只是麻烦了点(要多通信两次,第 ...

随机推荐

  1. Netsharp快速入门(之16) Netsharp基础功能(权限管理)

    第5章     Netsharp基础功能 5.1     权限配置 5.1.1  功能权限 1.配置权限功能点,打开平台工具-基础业务-操作管理 2.选择资源节点为销售订单,点添加常用操作,添加完成后 ...

  2. UVALive - 6575 Odd and Even Zeroes 数位dp+找规律

    题目链接: http://acm.hust.edu.cn/vjudge/problem/48419 Odd and Even Zeroes Time Limit: 3000MS 问题描述 In mat ...

  3. 01.Redis安装

    1.安装Redis 1.下载.解压Redis [lizhiwei@localhost Redis]$ ll total 1248 -rwxrwxr-x. 1 lizhiwei lizhiwei 127 ...

  4. 【BZOJ】【1023】【SHOI2008】cactus仙人掌图

    DP+单调队列/仙人掌 题解:http://hzwer.com/4645.html->http://z55250825.blog.163.com/blog/static/150230809201 ...

  5. 【BZOJ】【1003】【ZJOI2006】物流运输trans

    最短路/DP 这题数据规模并不大!!这是重点……… 所以直接暴力DP就好了:f[i]表示前 i 天的最小花费,则有$f[i]=min\{f[j]+cost[j+1][i]+k\} (0\leq j \ ...

  6. frequentism-and-bayesianism-chs-iii

    frequentism-and-bayesianism-chs-iii   频率主义 vs 贝叶斯主义 III:置信(Confidence)与可信(Credibility),频率主义与科学,不能混为一 ...

  7. StoreKit framework

    关于In-APP Purchase 1. 中文文档 基本流程: http://www.cnblogs.com/wudan7/p/3621763.html 三种购买形式及StoreKit code介绍: ...

  8. HDOJ 1398 Square Coins 母函数

    Square Coins Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Tota ...

  9. css两个form不换行,两个div并排代码

    1.form不换行通过table布局实现 <table> <tr> <td> <form method="get" action=&quo ...

  10. BZOJ2463: [中山市选2009]谁能赢呢?

    感慨下汉堡的找水题能力… /************************************************************** Problem: 2463 User: zhu ...