我试图将标签从拉丁语打印到cyrilic,这些是我尝试了很多次但没有成功的方法,结果是:
System.Text.ASCIIEncoding: ????? ??????????
System.Text.UTF8Encoding: ИВÐÐÐ Ð’ÐСИЛЕВСКÐ
System.Text.UnicodeEncoding: ИВÐÐÐ Ð’ÐСИЛЕВСКÐ
我无法弄清楚我在这里做错了什么:
protected void Button1_Click(object sender, EventArgs e)
{
string path = @"c:\Kitchen\bar.xls";
if (!File.Exists(path))
{
using (StreamWriter sw = File.CreateText(path))
{
string cyrillicText = "ЗДРАВО НА СИТЕ";
string cyrillicText1 = "HELLO everyone";
System.Text.ASCIIEncoding encodingASCII = new System.Text.ASCIIEncoding();
System.Text.UTF8Encoding encodingUTF8 = new System.Text.UTF8Encoding();
System.Text.UnicodeEncoding encodingUNICODE = new System.Text.UnicodeEncoding();
byte[] textBytesASCII = encodingASCII.GetBytes(cyrillicText);
byte[] textBytesUTF8 = encodingUTF8.GetBytes(cyrillicText);
byte[] textBytesCyrillic = encodingUNICODE.GetBytes(cyrillicText);
byte[] textBytesCyrillic1 = encodingUNICODE.GetBytes(cyrillicText1);
sw.WriteLine("{0}: {1}", encodingASCII.ToString(), encodingASCII.GetString(textBytesASCII));
sw.WriteLine("{0}: {1}", encodingUTF8.ToString(), encodingUTF8.GetString(textBytesUTF8));
sw.WriteLine("{0}: {1}", encodingUNICODE.ToString(), encodingUNICODE.GetString(textBytesCyrillic));
sw.WriteLine("{0}: {1}", encodingUNICODE.ToString(), encodingUNICODE.GetString(textBytesCyrillic1));
System.Text.Encoding iso_8859_2 = System.Text.Encoding.GetEncoding("windows-1251");
System.Text.Encoding utf_8 = System.Text.Encoding.UTF8;
NameValueCollection n = HttpUtility.ParseQueryString("RT=Може",iso_8859_2 );
sw.Write(n["RT"]);
}
}
}