German letters and encoding in C#

前端 未结 2 963
北荒
北荒 2020-12-20 15:39

I have an unzipping function, and I am using System.Text.Encoding to make sure that the files that are being extracted keep the same names after extraction beca

2条回答
  •  别那么骄傲
    2020-12-20 16:19

    Try CodePage 850 (has worked for me):

    using (ZipArchive archive = System.IO.Compression.ZipFile.Open(ZipFile, ZipArchiveMode.Read,  System.Text.Encoding.GetEncoding(850)))
    {
          // ....
    

    The next comment is from (an ancient version) of Sharpziplib that put me in the right direction:

        /* Using the codepage 1252 doesn't solve the 8bit ASCII problem :/
           any help would be appreciated.
    
          // get encoding for latin characters (like ö, ü, ß or ô)
          static Encoding ecp1252 = Encoding.GetEncoding(1252);
        */
    
        // private static Encoding _encoding = System.Text.ASCIIEncoding;
        private static Encoding _encoding = System.Text.Encoding.GetEncoding(850);
    

    The last line is my change, to made it correctly read zip-files with special characters.

提交回复
热议问题