using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CS_Ansi2Unicode
{
class Program
{
static void Main(string[] args)
{
Encoding encode = Encoding.GetEncoding(“big5”);
/*
String StrInput=””;
StreamReader sr = new StreamReader(“ANSI.txt”, encode);
while (!sr.EndOfStream)// 每次讀取一行,直到檔尾
{
StrInput = sr.ReadLine();// 讀取文字到 line 變數
}
*/
String StrInput = File.ReadAllText(“ANSI.txt”, encode);
Encoding ascii = Encoding.GetEncoding(“big5”);//Encoding.ASCII;
Encoding unicode = Encoding.Unicode;
byte[] ansiBytes = ascii.GetBytes(StrInput);
byte[] unicodeBytes = Encoding.Convert(ascii, unicode, ansiBytes);
char[] unicodeChars = new char[unicode.GetCharCount(unicodeBytes, 0, unicodeBytes.Length)];
unicode.GetChars(unicodeBytes, 0, unicodeBytes.Length, unicodeChars, 0);
string StrOutput = new string(unicodeChars);
File.WriteAllText(“Unicode.txt”, StrOutput, Encoding.Unicode);
}
}
}
|