Chinaunix首页 | 论坛 | 博客
  • 博客访问: 734979
  • 博文数量: 769
  • 博客积分: 6000
  • 博客等级: 准将
  • 技术积分: 4985
  • 用 户 组: 普通用户
  • 注册时间: 2008-10-15 16:37
文章分类

全部博文(769)

文章存档

2011年(1)

2008年(768)

我的朋友

分类:

2008-10-15 16:38:16

 using System;
using System.IO;
using System.Text;
using System.Runtime.InteropServices;

//big5繁体转换简体的程序
public class EncodeTool
{
 
 [DllImport("kernel32.dll", EntryPoint = "LCMapStringA")]
    public static extern int LCMapString(int Locale, int dwMapFlags, byte[] lpSrcStr, int cchSrc, byte[] lpDestStr, int cchDest);
   
 const int LCMAP_SIMPLIFIED_CHINESE = 0x02000000;
 const int LCMAP_TRADITIONAL_CHINESE = 0x04000000;

    public static void Main (String[] args)
    {
  if (args.Length<1)
  {
   Console.WriteLine("请指定路径!");
  }
  String[] files=Directory.GetFiles(args[0]);
  if(args.Length==2)
   files=Directory.GetFiles(args[0],args[1]);
  String dir=args[0]+"";
  if(!Directory.Exists(dir)){
   Directory.CreateDirectory(dir);
  }
  for(int i=0;i   StreamReader sr = new StreamReader(files[i],Encoding.GetEncoding("big5"));
   String lines=sr.ReadToEnd();
   sr.Close();
   lines=ConvertString(lines);
   //Console.WriteLine(lines);
   StreamWriter sw = new StreamWriter(dir+""));
   sw.WriteLine(lines);
   sw.Close();
   Console.WriteLine("转换 {0} ok!",files[i]);
  }
 }

 public static String ConvertString(String lines){
  Encoding gb2312 = Encoding.GetEncoding(936);
  byte[] src=gb2312.GetBytes(lines);
  byte[] dest = new byte[src.Length];
  LCMapString(0x0804, LCMAP_SIMPLIFIED_CHINESE, src, -1, dest, src.Length);
  return gb2312.GetString(dest);
 }
}


--------------------next---------------------

阅读(450) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~