C # code for converting big5 traditional to simplified gb2312

Source: Internet
Author: User
Using system;
Using system. IO;
Using system. text;
Using system. runtime. interopservices;
// Big5 simplified Conversion Program
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 ("Please specify the path! ");
}
String [] files = directory. getfiles (ARGs [0]);
If (ARGs. Length = 2)
Files = directory. getfiles (ARGs [0], argS [1]);
String dir = ARGs [0] + "\ Conv ";
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 + "\" + files [I], false, encoding. getencoding ("gb2312 "));
Sw. writeline (lines );
Sw. Close ();
Console. writeline ("Convert {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 );
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.