-->

Detect the encoding from A DBF

2019-05-26 22:17发布

问题:

I want to detect the encoding of DBF automatically, but the structure of DBF file doesn't contains any information in the header of DBF file. I used to use a DBF Viewer and it opens with a proper encoding information. So I'm not sure how they implement it.

I researched the structure of DBF file and there is a language driver id, but we don't have an ID to CodePage table, any one have clue?

回答1:

I did a lot of research and found this article in Esri's official website: http://webhelp.esri.com/arcpad/8.0/referenceguide/index.htm#locales/task_code.htm

It really helps for me to convert from language id to code page; I this issue is fixed. Hope it helps others.



回答2:

I found this site too that has the header structural breakdown to get codepage information.

So this, in conjunction with the other answer might help you better resolve. The link I had doesn't list all the codepages, but does give you where and values for detecting from a .DBF

In addition, Visual Foxpro has some functions to get and convert too, but I haven't explicitly tried via the latest Visual Foxpro OleDB Provider that can be used with C#.

The functions are

CPDBF() CPCURRENT() CPCONVERT()

You can check online help for Visual Foxpro to get more details on these functions. You may have to do the C# via Execute Scalar call with VFP's EXECSCRIPT() call.. something like

String MultipleCmds = "ExecScript( '[use SomeTable] + chr(13)+chr(10) + [return CPCURRENT()]' ) ";

then from your connection, execute scalar of the command above.