FileEncoding PowerScript function
Description
Checks the encoding of the specified file.
Syntax
|
1 |
<span>FileEncoding</span> ( <span>filename </span>) |
|
Argument |
Description |
|---|---|
|
filename |
The name of the file you want to test |
Return Values
A value of the enumerated datatype Encoding. Values are:
-
EncodingANSI!
-
EncodingUTF8!
-
EncodingUTF16LE!
-
EncodingUTF16BE!
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
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:
|
1 |
long ll_filenum<br>integer li_bytes<br>string ls_unicode<br>blob lb_ansi<br>encoding eRet<br> <br>ll_filenum = FileOpen("employee.dat",StreamMode!,<br>   Read!, LockWrite!, Replace!)<br> <br>// test the file's encoding<br>eRet = FileEncoding("employee.dat")<br> <br>if eRet = EncodingANSI! then<br>   li_ bytes = FileReadEx(ll_filenum, lb_ansi)<br>   ls_unicode = string(lb_ansi, EncodingANSI!)<br>else <br>   li_ bytes = FileReadEx(ll_filenum, ls_unicode)<br>end if<br>FileClose(ll_filenum) |
See Also
Document get from Powerbuilder help
Thank you for watching.
Subscribe
Login
0 Comments
Oldest