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. android 通过工具抓包

    工具: 1.tcpdump :http://www.strazzere.com/android/tcpdump 2.wireshark:http://pan.baidu.com/s/1geooiav ...

  2. 面向对象版js分页

    基于前一个js分页,我将代码改成一个面向对象版的js分页,代码如下 http://peng666.github.io/blogs/pageobj <!DOCTYPE html> <h ...

  3. css3动画实例

    <!doctype html> <html> <head> <meta charset="utf-8"> <title> ...

  4. 土地购买 usaco 斜率优化

    看这道题的时候,感觉很难,因为数据范围比较大,很难dp: 后来想到了[书柜的尺寸]这道题,也是一道dp,曾经看了那道题的题解而深有启发: 这道题每组的付费只与这一组长宽的最大值有关,也就是说要分组,一 ...

  5. 【面试题043】n个骰子的点数

    [面试题043]n个骰子的点数 题目:     把n个骰子扔在地上,所有骰子朝上一面的点数之和为s, 输入n,打印出s的所有可能的值出现的概率.   n个骰子的总点数,最小为n,最大为6n,根据排列组 ...

  6. HDU 4576 Robot(概率dp)

    题目 /*********************复制来的大致题意********************** 有N个数字,M个操作, 区间L, R. 然后问经过M个操作后落在[L, R]的概率. * ...

  7. git的安装使用和代码自动部署

    1.安装 http://www.cnblogs.com/sunada2005/archive/2013/06/06/3121098.html http://www.cnblogs.com/zhcncn ...

  8. 强大的grep命令

    1.作用 Linux系统中grep命令是一种强大的文本搜索工具,它能使用正则表达式搜索文本,并把匹 配的行打印出来.grep全称是Global Regular Expression Print,表示全 ...

  9. C# 设置程序开机自动运行(+注册表项)

    有时候我们需要让软件安装好了,开机自动运行,这时我们需要把启动项加载到注册表中,需要注意的时现在很多杀毒软件在其他软件更改注册表的时候会有提示,可能会阻止.下面代码包含增加启动项到注册表和删除启动项. ...

  10. light oj 1205 - Palindromic Numbers 数位DP

    思路:搜索的时候是从高位到低位,所以一旦遇到非0数字,也就确定了数的长度,这样就知道回文串的中心点. 代码如下: #include<iostream> #include<cstdio ...