当前位置:   article > 正文

c#UTF8编码文件简体、繁体互转_c# utf-8转中文

c# utf-8转中文

该代码可将QQ国际版的繁体中文文件转换为简体中文文件(文件编码需UTF8)

Form1.cs --需引用Microsoft.VisualBasic.dll 

  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Text;
  7. using System.Windows.Forms;
  8. using System.IO;
  9. using System.Threading;
  10. using Microsoft.VisualBasic;
  11. namespace WindowsApplication1
  12. {
  13. public partial class Form1 : Form
  14. {
  15. public Form1()
  16. {
  17. InitializeComponent();
  18. }
  19. private void button1_Click(object sender, EventArgs e)
  20. {
  21. label2.Text = "";
  22. string path = textBox1.Text;
  23. if (Directory.Exists(path))
  24. {
  25. string newpath = path + "\\已翻译文件_" + (radioButton1.Checked ? "繁体" : "简体");
  26. if (!Directory.Exists(newpath)) Directory.CreateDirectory(newpath);
  27. button1.Enabled = false;
  28. new Thread(delegate()
  29. {
  30. int failCount = 0;
  31. string[] filenames = Directory.GetFiles(path);
  32. //遍历指定文件夹的文件
  33. for (int i = 0; i < filenames.Length; i++)
  34. {
  35. this.Invoke(new MethodInvoker(delegate() { label2.Text = "共" + filenames.Length + "个文件,正在翻译第" + (i + 1) + "个"; }));
  36. try
  37. {
  38. //读取文件内容
  39. string text = File.ReadAllText(filenames[i], Encoding.UTF8);
  40. //繁体、简体互转
  41. string newtext = Strings.StrConv(text, radioButton1.Checked ? VbStrConv.TraditionalChinese : VbStrConv.S
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/很楠不爱3/article/detail/253416
推荐阅读
相关标签
  

闽ICP备14008679号