Language Reference Guide : System Classes : StringObject Class : FileEncoding Attribute
 
Share this page          
FileEncoding Attribute
Data Type: integer
4GL Access: RW
The FileEncoding attribute specifies what encoding format to use when writing a StringObject using the WriteToFile method (see UpdateInDB Method) or AppendToFile Method.
When FileHandle Attribute) is set, a file will be read in and converted, if necessary, before being assigned to a StringObject. When the WriteToFile method is executed, the content of the StringObject will be written out with the encoding format specified by the FileEncoding attribute.
When the AppendToFile method is executed on a StringObject, its content will be written out with the specified FileEncoding regardless of its existing encoding format.
If a character in the string cannot be converted, the default substitute character '?' will be used. '?' is used because it is a valid character in all character sets.
Note:  Even if an incorrect encoding is specified, no data will be lost through translation.
You can set FileEncoding to one of the following constants:
FE_DEFAULT
Specifies that the file encoding format is the same as that which OpenROAD currently uses. This means that if II_CHARSETxx is UTF8, then UTF8 encoding is used. For any other setting, its active code page is used.
FE_WCHAR
Specifies that the file is generated using wide-char APIs that are in the same format (size and endian) as the system that OpenROAD is running on.
FE_ACP
Specifies that the file encoding format is the current system active code page. For example, if II_CHARSETxx is UTF8, the file format could be WIN1252 if that is the current active code page.
code_page_identifier
Specifies a Microsoft code page identifier, for example, 1252 for ANSI Latin 1/Western European (Windows)
Default: FE_DEFAULT
Microsoft code page identifiers are listed at http://msdn.microsoft.com/en-us/library/windows/desktop/dd317756%28v=vs.85%29.aspx.
All code pages are supported on Microsoft Windows platforms. Only the following subset of code pages is supported on UNIX systems: 037, 437, 500, 708, 720, 737, 775, 850, 852, 855, 857, 860, 861, 862, 863, 864, 865, 866, 869, 870, 874, 875, 932, 936, 949, 950, 1026, 1200, 1201, 1250, 1251, 1252, 1253, 1254, 1255, 1256, 1257, 1258, 1361, 10000, 10001, 10002, 10003, 10004, 10005, 10006, 10007, 10008, 10010, 10017, 10029, 10079, 10081, 10082, 20127, 20865, 20866, 28591, 28592, 29001, 65001.
Descriptions of system constant values and their numeric equivalents are listed in FileEncoding Settings.
The following examples assume that there is a StringObject named str_var containing 'this costs €23'.
To write the string value with default encoding:
Str_var.WriteToFile('c:\temp\default_encoding.txt');
To write the string value with UTF8 encoding:
Str_var.FileEncoding = 65001;
Str_var.WriteToFile('c:\temp\utf8_encoding.txt');
To write the string value with UTF16-LE encoding:
Str_var.FileEncoding = 1200;
Str_var.WriteToFile('c:\temp\utf16_le_encoding.txt');
To write the string value with code page 1252 encoding:
Str_var.FileEncoding = 1252;
Str_var.WriteToFile('c:\temp\cp1252_encoding.txt');
To write the string value with ISO-8859-1 encoding:
Str_var.FileEncoding = 28591;
Str_var.WriteToFile('c:\temp\iso8859_1_encoding.txt');