Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2017-11

Guessing the encoding of some text

8 messages · 5 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Torsten Bonde Christiansen

Hi List.

I am reading some text of some .csv files, but the encoding of the files is not always the same. In fact it may vary greatly from a lot of european encodings, UTF8 and asian encoding.

I have tried using the function GuessEncoding(..) in LConvEncoding.pas, but from the source code I can see that it mostly focuses on BOM's and ASCII/UTF-8

Does Lazarus or FPC include other convinient tools that may detect the encoding of (the content of) a file?
What do others do in this situation?

My goal is to convert all the read text to UTF-8.

Kind regards,
Torsten.

Reply by email

José Mejuto
to Torsten Bonde Christiansen: Hi List. I am reading some text of some .csv files, but the encoding of the files is not…
Torsten Bonde Christiansen wrote 6 lines
Hi List. I am reading some text of some .csv files, but the encoding of the files is not always the same. In fact it may vary greatly from a lot of european encodings, UTF8 and asian encoding.

Hello,

Some years ago I wrote a code that must be trained which guess encoding and language. The problems are that it must be trained with large texts and of course the result are only statistical and only quite good over quite large texts (like 1000 chars or more) so it is not good for single sentences.

If you are interested I can dive into old codes to catch it.

Reply by email

Zoë Peterson
to Torsten Bonde Christiansen: Hi List. I am reading some text of some .csv files, but the encoding of the files is not…
Torsten Bonde Christiansen wrote
Does Lazarus or FPC include other convinient tools that may detect the encoding of (the content of) a file? What do others do in this situation?

If you need cross-platform, this works with some trivial changes:

http://chsdet.sourceforge.net/

If you're Windows only, Microsoft provides
IMultiLanguage2.DetectInputCodepage():

https://msdn.microsoft.com/en-us/library/aa740986(v=vs.85).aspx

Zoë Peterson Scooter Software

Reply by email

Torsten Bonde Christiansen
to Zoë Peterson
Zoë Peterson wrote 8 lines
On 11/16/2017 4:25 AM, Torsten Bonde Christiansen via Lazarus wrote: > Does Lazarus or FPC include other convinient tools that may detect > the encoding of (the content of) a file? > What do others do in this situation? If you need cross-platform, this works with some trivial changes: http://chsdet.sourceforge.net/

Thanks - this is just what I was looking for.

Regards,
Torsten.

Reply by email