读取DBF文件的Utf8编码问题 [英] Utf8 encoding problem reading DBF File
本文介绍了读取DBF文件的Utf8编码问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想读一个德语的dbf文件。它包含ASCII编码不提供的变音符号。我试图用Encoding.UTF8替换Encoding.ASCII,但没有成功。 ByteReader也处于UTF8模式。我使用了这个很棒的片段
将DBF加载到DataTable [ ^ ]
有人可以帮帮我吗? :D
BTW抱歉我的英文不好。
Hi, I want to read a German dbf file. It contains umlauts which are not available in ASCII encoding. I tried to replace the "Encoding.ASCII" with "Encoding.UTF8", but without success. The ByteReader is in UTF8 mode too. I used this great snippet
Load a DBF into a DataTable[^]
Can someone help me please? :D
BTW Sorry for my bad English.
推荐答案
DBF不支持UTF8。您可能应用了一个代码页(我认为是1252),而人们在PC-s上调用ASCII只是其中一个代码页(437)。您可以使用 Encoding.Convert [ ^ ]将数据转换为utf8的方法。
这样的事情:
DBF is not supporting UTF8. You probably have a code page applied (1252 I suppose), than what people call ASCII on PC-s is only one of the code pages (437). You can use Encoding.Convert[^] method to convert the data to utf8.
Something like this:
Encoding wind1252 = Encoding.GetEncoding(1252);
Encoding utf8 = Encoding.UTF8;
byte[] wind1252Bytes = ...; //what you have read from the dbf field
byte[] utf8Bytes = Encoding.Convert(wind1252, utf8, wind1252Bytes);
string utf8String = Encoding.UTF8.GetString(utf8Bytes);
(来源: http://stackoverflow.com/questions/5568033/ convert-a-strings-character-encoding-from-windows-1252-to-utf-8 [ ^ ])
当我遇到问题时ASCII编码帮助我阅读了Joel On Software的文章[ ^ ]
我不能保证它会对你有所帮助,但也可能。
When I had problems with ASCII encoding it helped me reading this Joel On Software article[^]
I can't promise it will help you, but it may.
这篇关于读取DBF文件的Utf8编码问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文