JulesVerne
JulesVerne

Reputation: 53

Best practice to determine the codepage of an unkown file? (with Progress-4GL Openedeg)

What is the best way to identify the codepage of a file? I hoped i can use DetectInputCodepage but i dont know how to implement it with progress.

Upvotes: 0

Views: 345

Answers (1)

Jensd
Jensd

Reputation: 8011

I don't know what led you down that rabbit hole - the link you provided led to outdated documentation for Internet Explorer.

However. This problem is non trivial. See https://community.progress.com/s/article/000057930

Also

How can I detect the encoding/codepage of a text file?

Based on the answer above (on Stackoverflow) you can download the mentioned Nu-package and extract the dll (using any zip-tool).

Add the ude.dll-file to your assemblies and then you can do like this (error checking etc missing in this example):

USING Ude.*.
USING System.IO.*.

DEFINE VARIABLE fs  AS FileStream          NO-UNDO.
DEFINE VARIABLE ude AS CharsetDetector NO-UNDO.


fs = NEW FileStream( "c:/temp/test.txt", FileMode:Open).
ude = NEW CharsetDetector().

ude:Feed(fs).
ude:DataEnd().

IF ude:Charset <> ? THEN 
    MESSAGE SUBSTITUTE("Charset &1, confidence &2", ude:Charset, ude:Confidence) VIEW-AS ALERT-BOX.
ELSE 
    MESSAGE "Failed" VIEW-AS ALERT-BOX.

fs:Close().

DELETE OBJECT fs.
DELETE OBJECT ude.

Upvotes: 4

Related Questions