Absent Member.
Absent Member.
1245 views

ASCII to UTF-8 conversion and displaying in a list box

I have found that national characters like ÄÖüß and so on do not show correctly in a UTF-8 coded managed application when read from an ASCII file created by a native app.

Based on an answer I read here on encoding I came up with this code:

method-id UTF_conversion.
procedure division.

*> Specify the code page to correctly interpret byte values
set wsEncoding to type Encoding::GetEncoding(1252) *> Windows
set codePageValues to Auftragrec *> sequential file to be displayed
set n3 to codePageValues::Length *> set Original length of ASCII
set tAUFTRAGrec to Auftragrec *> save record to temporary record
*> Same content is now encoded as UTF-8
set unicodeValues to wsencoding::GetString(codePageValues)
set cAUFTRAGrec to unicodevalues *> for Display 
*> Same content "äöüß" is stored as UTF-8

initialize Auftragrec
set A-Empfaenger to cA-Empfaenger *> set item containing national characters displayed in list box as only data
set Auftragpath to Auftrags-datei *> save path for temporary usage
set Auftrags-datei to Tempdatei
invoke type System.IO.File::WriteAllText(Auftrags-datei, unicodeValues)
set compareValues to type System.IO.File::ReadAllBytes(Auftrags-datei)
set n4 to compareValues::Length *> new unicode length
subtract n3 from n4 giving n2 *> add n2 to length of display item in Listbox

call "CBL_DELETE_FILE" using Auftrags-datei
returning return-code
* reset values
set Auftragrec to tAuftragrec
set Auftrags-datei to AuftragPath
goback

end method.

it is quite awkward and my question is: Can I get the new length without saving and re-reading the file? It is necessary because the national characters don't seem to be recognized as such in a list box and without setting the field length to - length + No. of national chars - the displayed fields vary in size.

I cannot just convert and save the file because when printing, the result of CHAR to OEM conversion doesn't work.

But maybe I'm just using the wrong code?

0 Likes
0 Replies
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.