Help & Manual authoring tool
How to read DOS files with special characters

Reading DOS files with special characters

Copyright © 2000 Ernesto De Spirito

SMImport - Native VCL components for importing data

Sometimes we have to read legacy DOS files saved with DOS applications. There's no problem with the reading itself, but Windows and DOS by default use different code pages for the mapping of special ASCII characters.

For example, in DOS (code page 437 -IBM standard- and some other code pages typically used in DOS), the "registered" symbol ('®') is represented in a byte with the value 169. However, in Windows (code page 1252 and some other code pages typically used in Windows), the value 169 corresponds to the copyright symbol ('©') and the "registered" symbol ('®') has a value of 174. Something similar hapens with other symbols like accented characters for example.

If the data read from a DOS file is to be displayed or saved in Windows format we have to convert the characters (for example all 169 values to 174 and so on) so that they are correctly represented in Windows. The OemToChar API function can be used to convert a string variable in-situ:

uses Windows;

...
var
  s: string;
  ...
begin
  ...
  OemToChar(PChar(s), PChar(s));
  ...
end;
The inverse conversion (i.e. from Windows to DOS) can be achieved using the CharToOem API function.

JfControls Library - for Delphi and C++ Builder
Copyright © 2000/2006 Ernesto De Spirito.   All rights reserved.