熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> .NET編程 >> 正文

C#中將Big5繁體轉換簡體GB2312的代碼

2022-06-13   來源: .NET編程 

 using System;
using SystemIO;
using SystemText;
using SystemRuntimeInteropServices;

//big繁體轉換簡體的程序
public class EncodeTool
{
 
 [DllImport(kerneldll EntryPoint = LCMapStringA)]
    public static extern int LCMapString(int Locale int dwMapFlags byte[] lpSrcStr int cchSrc byte[] lpDestStr int cchDest);
   
 const int LCMAP_SIMPLIFIED_CHINESE = x;
 const int LCMAP_TRADITIONAL_CHINESE = x;

    public static void Main (String[] args)
    {
  if (argsLength<)
  {
   ConsoleWriteLine(請指定路徑!);
  }
  String[] files=DirectoryGetFiles(args[]);
  if(argsLength==)
   files=DirectoryGetFiles(args[]args[]);
  String dir=args[]+\\conv;
  if(!DirectoryExists(dir)){
   DirectoryCreateDirectory(dir);
  }
  for(int i=;i   StreamReader sr = new StreamReader(files[i]EncodingGetEncoding(big));
   String lines=srReadToEnd();
   srClose();
   lines=ConvertString(lines);
   //ConsoleWriteLine(lines);
   StreamWriter sw = new StreamWriter(dir+\\+files[i]falseEncodingGetEncoding(gb));
   swWriteLine(lines);
   swClose();
   ConsoleWriteLine(轉換 {} ok!files[i]);
  }
 }

 public static String ConvertString(String lines){
  Encoding gb = EncodingGetEncoding();
  byte[] src=gbGetBytes(lines);
  byte[] dest = new byte[srcLength];
  LCMapString(x LCMAP_SIMPLIFIED_CHINESE src dest srcLength);
  return gbGetString(dest);
 }
}


From:http://tw.wingwit.com/Article/program/net/201311/15082.html
  • 上一篇文章:

  • 下一篇文章:
  • 推薦文章
    Copyright © 2005-2022 電腦知識網 Computer Knowledge   All rights reserved.