FileEncoding

Description

Checks the encoding of the specified file.

Syntax

FileEncoding ( filename )

Argument

Description

filename

The name of the file you want to test for encoding type

Returns

A value of the enumerated datatype Encoding. Values are:

If filename does not exist, returns null.

Usage

Use this function to determine the encoding used in an external file before attempting to use it in a PowerBuilder application.

Examples

Example 1

The following example opens a file in stream mode and tests to determine whether it uses ANSI encoding. If it does, it reads data from the file into a blob and uses the String function to convert the blob to a Unicode string:

long ll_filenum
integer li_bytes
string ls_unicode
blob  lb_ansi
encoding eRet

ll_filenum = FileOpen("employee.dat",StreamMode!,
   Read!, LockWrite!, Replace!)

// test the file’s encoding
eRet = FileEncoding("employee.dat")

if eRet = EncodingANSI! then
   li_ bytes = FileReadEx(ll_filenum, lb_ansi)
   ls_unicode = string(lb_ansi, EncodingANSI!)
else 
   li_ bytes = FileReadEx(ll_filenum, ls_unicode)
end if
FileClose(ll_filenum)

See also