求大神指点 vb.net 怎么把Unicode转换成Ansi
发布网友
发布时间:2023-09-09 09:52
我来回答
共1个回答
热心网友
时间:2024-02-16 20:31
using System.IO;
using System.Text;
// convert DBCS-932 encoded file to unicode-file
Encoding ecp932 = Encoding.GetEncoding( 932 );
StreamReader sr = new StreamReader( @"C:\cp932.txt", ecp932, false );
StreamWriter sw = new StreamWriter( @"C:\unicode.txt", false,
Encoding.Unicode );
sw.Write( sr.ReadToEnd() );
sw.Close();
sr.Close();
// convert unicode-file to ANSI text file
Encoding ecp1252 = Encoding.GetEncoding( 1252 );
sr = new StreamReader( @"C:\unicode.txt", Encoding.Unicode, false );
sw = new StreamWriter( @"C:\cp1252.txt", false, ecp1252 );
sw.Write( sr.ReadToEnd() );
sw.Close();
sr.Close();