Parameter | Description |
---|---|
sName | The fully qualified name of the file to read |
eInEncoding | The file's character encoding format, which may be OEM (CP_OEMCP), ANSI (CP_ACP), UTF-8 (CP_UTF8) or UTF-16 (-1) |
The contents of the file to a Variant string
Function ReadFileToVariantStr String sName Integer eInEncoding Returns Variant
Call: | Get ReadFileToVariantStr sName eInEncoding to VariantVariable |
ReadFileToVariantStr reads a sequential file and moves the contents to a Variant string. The encoding format must be specified (OEM, ANSI, UTF-8 or UTF-16). The data will be converted to Unicode when stored in the Variant string.
Using a Variant string means you do not need to worry about disposing of the data and the data will be converted and stored as Unicode within the Variant. Refer to cCharTranslate for a complete description of using Variant strings for this purpose.
You must know in advance what the character encoding format of the file is. The file will most likely be in OEM (CP_OEMCP), ANSI (CP_ACP) or UTF-8 (CP_UTF8) format. If you choose the wrong format, the conversion to a Variant Unicode string may result in a conversion error.
// read in an OEM document to a variant Move (sAppSrc +"\OEM Document.txt") to sName Get ReadFileToVariantStr of oFileHelper sName CP_OEMCP to v1 // read in a ANSI document to a variant Move (sAppSrc +"\ANSI Document.txt") to sName Get ReadFileToVariantStr of oFileHelper sName CP_ACP to v2 // read in a UTF-8 document to a variant Move (sAppSrc +"\UTF8 Document.txt") to sName Get ReadFileToVariantStr of oFileHelper sName CP_UTF8 to v3 // read in a UTF-16 document to a variant (would be unusual to have a UTF-16 file) Move (sAppSrc +"\UTF16 Document.txt") to sName Get ReadFileToVariantStr of oFileHelper sName -1 to v4
Use WriteFileFromVariantStr to create a file in a specified format encoding format.