大家好,
目前想要把 UTF-8 的文字檔轉成 ISO-8859-1 的格式
希望轉完後不要動到原始圖案 (如Ⓡ、®等)
嘗試以下方式撰寫:
// Transfer UTF-8 to ISO-8859-1
Encoding iso = Encoding.GetEncoding("iso-8859-1");
Encoding utf8 = Encoding.UTF8;
byte[] utfBytes = utf8.GetBytes(response);
byte[] isoBytes = Encoding.Convert(utf8, iso, utfBytes);
response = iso.GetString(isoBytes);
System.IO.File.WriteAllText(Filename, response, Encoding.GetEncoding("iso-8859-1"));
return true;
結果發現 WriteAllText 裡面的 Encoding.GetEncoding("iso-8859-1")
好像沒有作用。用 Notepad++ 開啟時還是 UTF-8
請問還有其他方式可以存成 ISO-8859-1 嗎??
謝謝
ps.
有試過將文字複製後,用 notepad++ 轉成 iso-8859-1 再貼回去並存檔
是可以正常顯示圖案的。(圖案有支援iso-8859-1)
結論:
自己犯傻了,在讀取至 response 時,寫成 Encoding.Default
應該要用 Encoding.UTF8 才對。
(雖然不知道為何會影響到輸出)