德信和编码在C# [英] German letters and encoding in C#
问题描述
我有一个解压缩功能,我使用 System.Text.Encoding
以确保正在提取文件保持相同的名字提取后因为通常我是解压包含字母德国的文件。结果
我试着像 Encoding.Default
或 Encoding.UTF8 $不同的事情C $ C>但没有任何工程
äÄéöÖüß.txt
被转换为Z™A.TXT
或在默认情况下,它是黑盒子:/
有什么建议?
使用(ZipArchive存档= System.IO.Compression.ZipFile.Open(ZipFile中,ZipArchiveMode.Read,System.Text.Encoding在archive.Entries .DEFAULT))
{
的foreach(ZipArchiveEntry进入)
{
串FULLPATH = Path.Combine(APPPATH,entry.FullName);
如果(String.IsNullOrEmpty(entry.Name))
{
Directory.CreateDirectory(完整路径);
}
,否则
{
如果(!entry.Name.Equals(Updater.exe))
{
entry.ExtractToFile(完整路径,真正);
}
}
}
}
尝试代码页850(已为我工作):
(ZipArchive存档= System.IO.Compression.ZipFile.Open(ZipFile中,ZipArchiveMode.Read,System.Text.Encoding.GetEncoding(850)))
{
// ...
接下来的注释是从Sharpziplib的(一种古老的版本),这让我在正确的方向:
/ *使用的代码页1252不能解决8位ASCII问题:/
任何帮助,将不胜感激。
//获得拉丁字符编码(如ö,ü,ß或O)
静态编码ecp1252 = Encoding.GetEncoding(1252);
* /
//私有静态编码_encoding = System.Text.ASCIIEncoding;
私有静态编码_encoding = System.Text.Encoding.GetEncoding(850);
最后一行是我的变化,使其正确读取有特殊字符拉链文件。
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 because usually the files that I am unzipping contains German letters.
I tried different things like Encoding.Default
or Encoding.UTF8
but nothing works
äÄéöÖüß.txt
gets converted to „Ž‚"™á.txt
or in case of default it is black boxes :/
any suggestions?
using (ZipArchive archive = System.IO.Compression.ZipFile.Open(ZipFile, ZipArchiveMode.Read, System.Text.Encoding.Default))
{
foreach (ZipArchiveEntry entry in archive.Entries)
{
string fullPath = Path.Combine(appPath, entry.FullName);
if (String.IsNullOrEmpty(entry.Name))
{
Directory.CreateDirectory(fullPath);
}
else
{
if (!entry.Name.Equals("Updater.exe"))
{
entry.ExtractToFile(fullPath,true);
}
}
}
}
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.
这篇关于德信和编码在C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!