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. UVA 10004 Bicoloring

    题目链接:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=12&pa ...

  2. JSP for query

    1. JSP中部分常用标签: Form.jsp <%@ page contentType="text/html;charset=UTF-8" language="j ...

  3. max_flow(Edmond_Karp) 分类: ACM TYPE 2014-09-02 10:47 92人阅读 评论(0) 收藏

    #include <cstdio> #include <iostream> #include <cstring> #include<queue> usi ...

  4. 来自平时工作中的javascript知识的积累---持续补充中

    ① SeaJs和RequireJS最大的区别 解惑:来自豆友 ② javascript中如何判断undefined var exp = undefined; if (exp === undefined ...

  5. ajax跨域请求,页面和java服务端的写法

    方法一(jsonp): 页面ajax请求的写法: $.ajax({ type : "get", async : false, cache : false, url : " ...

  6. Core Data数据库迁移

    一. Lightweight Migration i. 适合场景 Simple addition of a new attribute Removal of an attribute A non-op ...

  7. jQuery实现 浏览器后退到上次浏览位置

    近日看腾讯.新浪的移动端网站,发现一件非常蛋疼的事情,在列表浏览内容,我往下翻,往下翻,突然,看到一个十分霸气的标题,于是点到文章查看详细内容,若干时间后,点回退按钮,浏览器回退到页面的最顶部了. 于 ...

  8. POJ 1969

    #include <iostream> #include <cmath> using namespace std; int main() { //freopen("a ...

  9. Android的px、dip、sp的区别

    Android的px.dip.sp的区别 我们在页面布局的时候,经常会设置容器的长度,但是到底该使用哪个作为长度的单位而懊恼. 在Android中支持的描述大小区域的类型有以下几种:   px(pix ...

  10. Tomcat内存溢出(java.lang.OutOfMemoryError: PermGen space)的解决办法

    Tomcat启动时报如下错误: java.lang.OutOfMemoryError: PermGen space 解决办法: 配置相关内存大小.其中按照启动tomcat的不同方式,分如下三种情况 a ...