Search code examples
openedgeprogress-4glcodepages

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.


Solution

  • 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.