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. 再论 ASP.NET 中获取客户端IP地址

    说到IP获取无非是我们常见的以下几种方式,但是具体获取的值具体区别在哪?网上不乏相关文章,说的也是很详细,但是真正使用起来,还有很多不太对的地方.IP在不同系统中,应用相当广泛,常见的日志记录.广告分 ...

  2. 【Unique Binary Search Trees II】cpp

    题目: Given n, generate all structurally unique BST's (binary search trees) that store values 1...n. F ...

  3. 【Count and Say】cpp

    题目: The count-and-say sequence is the sequence of integers beginning as follows:1, 11, 21, 1211, 111 ...

  4. vi中正则表达式的使用

    在当前行中删除从aa到zz的所有字符 :s/aa.*zz//在整个文件用and代替所有的&字符:1,$s/&/and/g在每一行的首行插入字符串new:1,$s/^/new/g在第二行 ...

  5. Chapter 3 Discovering Classes and Object

    Chatper 3 Discovering Classes and Object Exercises: 1.What is a class? A class is a template for man ...

  6. Ubuntu 部署 Redmine

    我是在虚拟机种安装的Ubuntu,原因是装双系统太麻烦,虚拟机有问题的话删除容易. 首选保证主机中能ping 通虚拟机.我是用的桥接. 1.ubuntu安装必备的软件: sudo apt-get in ...

  7. 临时文档9--dfs

    #include<iostream> #include<stdio.h> #include<math.h> #include<string.h> usi ...

  8. ACM入门记

    [2015.12]零基础进队 [2016.4.10]浙大第十六届程序设计大赛 [2016.6.4]团体程序设计天梯赛初赛 [2016.7.16]团体程序设计天梯赛决赛 赛后总结:比赛的时候好慌,一道题 ...

  9. Altium Designer 使用小结

    今天刚把做好的PCB文件交给工厂去制板,阶段工作告一段落,来一个小总结. 前一段时间复习完C语言之后,在中国知网上搜索用单片机实现的小制作,找比较有意思,又不需要太多外专业知识的东西,然后就相中了超声 ...

  10. PHPStorm+PHP5.6+WIN7+IIS7

    文件下载 以下为参考网址,如无法打开或变动,请自行搜索,获取最新版本文件请行搜索 PHP Manager:http://www.iis.net/downloads/community/2010/09/ ...