c# 文件简繁体转换
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# 文件简繁体转换的更多相关文章
- 我的Android进阶之旅------>Android中如何高效率的进行简繁体转换
因为APP要做国际化适配,所以就需要顾及到香港和台湾都是使用繁体字,怎样快速便捷高效的把简体字转换成繁体字呢? 说实话我之前用的方法比较呆板,把每个需要转换的字符串进行在线翻译.今天突然发现word或 ...
- Python实现简繁体转换,真的玩得花
大家好鸭, 我是小熊猫 直接开搞!!! 1.opencc-python 首先介绍opencc中的Python实现库,它具有安装简单,翻译准确,使用方便等优点.对于我们日常的需求完全能够胜任. 1.1安 ...
- asp.net简繁体转换
简繁体转换添加Microsoft.VisualBasic.dll引用 //简转繁 string str= Microsoft.VisualBasic.Strings.StrConv("民生银 ...
- Delphi汉字简繁体转换代码(分为D7和D2010版本)
//delphi 7 Delphi汉字简繁体转换代码unit ChineseCharactersConvert; interface uses Classes, Windows; type T ...
- 利用js轻松实现页面简繁体转换
使用方法:StranBody(); //转换对象,使用递归,逐层剥到文本 function StranBody(fobj) { if(typeof(fobj)=="object") ...
- C#简繁体转换
/// <summary>/// 字符串简体转繁体/// </summary>/// <param name="strSimple"></ ...
- js搞定网页的简繁转换
对网页进行简繁字体转换的方法一般有两种:一是使用<简繁通>这样的专业软件,另外一种是制作两套版本的网页.显然,这两种方法都较为麻烦,而且专业软件一般不能用于免费的空间.笔者在这里给大家提供 ...
- 简繁体互换工具:opencc
简繁体互换工具:opencc opencc是一个简体.繁体相互转换的命令行工具. 安装 下载软件包.在下载页面下载软件包(如1.0.4版本) 解压.通过命令解压:tar -xzvf opencc-1. ...
- js如何实现简繁体互转
js如何实现简繁体互转 一.总结 一句话总结:其实无论是简体还是繁体,都是在显示端(前端),其实所有的我只用动js就好了,没必要动php. 当然,后端也可以做前端的事情,只是麻烦了点(要多通信两次,第 ...
随机推荐
- android中 回调方法,怎么转变为阻塞执行的方法
项目中需要用到在wifi这一块,扫描附近wifi,然后一个个遍历所有wifi,并且尝试连接,所以就在这里需要每连接一个wifi进行阻塞,当连接失败的时候才进行尝试下一个连接,当连接成功时则break. ...
- function的prototype
prototype只有function才有的属性. var a = function() { this.age = 12; this.name = "haha"; }; a.pro ...
- hadoop开发环境-----eclipse
1.eclipse下载 http://www.eclipse.org/downloads/packages/eclipse-ide-java-ee-developers/lunasr1 2.hadoo ...
- WCF Service的Restfull风格
怎样构建? •您需要什么样的资源? •将使用哪些 URI 表示这些资源? •每个 URI 将支持统一接口的哪些部件(HTTP 动词)? URI的处理 •UriTemplate –System ...
- iOS项目的完整重命名方法图文教程
原文链接:http://www.cocoachina.com/ios/20150104/10824.html iOS项目的完整重命名方法图文教程 前言:在iOS开发中,有时候想改一下项目的名字,都会遇 ...
- 深入浅出ES6(十三):类 Class
作者 Jason Orendorff github主页 https://github.com/jorendorff 你可能觉得之前讲解的内容略显复杂,今天我们就讲解一些相对简单的内容,不再是生成器 ...
- 网站建设底层知识Socket与Http解析
在进行网站建设的时候,常常遇到不同的协议,Socket和http协议都可以实现数据传输,但两种传输方式在网站建设中有什么各自的特点,和缺点,如何选择合适的传输方式. 1 数据传输方式 1.1 Soc ...
- Could not create the driver from NHibernate.Driver.SQLite20Driver
使用NHibernate连接Sqlite语句,版本为.net3.5. 升级.net 4.0出现异常,提示”Could not create the driver from NHibernate.Dri ...
- mp3 音频 音乐 tag ID3 ID3V1 ID3V2 标签 读取信息 获得图片 jpeg bmp 图片转换等
mp3 音频 音乐 tag ID3 ID3V1 ID3V2 标签 读取信息 获得图片 jpeg bmp 图片转换(上) MP3文件格式(二)---ID3v2 图:ID3V1标签结构 图:ID3V2标签 ...
- 【转】SIP 中的Dialog,call,session 和 transaction
如果你对Sip协议中Call, Dialog, Transaction和Message之间的关系感觉到迷惑,那么,那么我可以告诉你,你并不孤单,因为大多数初学者对于这些名词之间的关系都会感到疑惑. ...