MyChat Scripts Engine: LoadTextFromFile
Upload a text file content to a string with the specified file encoding.
Syntax
function LoadTextFromFile(sFileName: string; iEncodingType: integer): string;
Parameters and return values
Parameter |
Type |
Value |
sFileName |
string |
name of a text file with a full path to it; |
iEncodingType |
integer |
file encoding type, number. |
Function result
If a file exists and is read with no errors, the function returns its contents (otherwise, the function returns an empty string).
Example
The function reads a text file contents in UTF-8 format from the C:\Temp\testmessage.txt folder and displays the result in the console, with/without decoding (a file must exist, you can create it manually or download for the test).
const
TEST_FILE = 'c:\temp\testmessage.txt';
var
s: string;
begin
if FileExists(TEST_FILE) then begin
s := LoadTextFromFile(TEST_FILE, 0);
mLogScript(s, 'AS IS');
s := LoadTextFromFile(TEST_FILE, 6);
mLogScript(s, 'UTF8');
end;
end.
Script work result
[11:09:22] (Log "LoadTextFromFile"): [AS IS] РџСЂРёРІРµС! РСРѕ СесСРѕРІРѕРµ СЃРѕРѕР±Сение РІ СРѕСЂРјР°СРµ UTF8!
[11:09:22] (Log "LoadTextFromFile"): [UTF8] Hello! This is a test message in UTF8 format!
[11:09:22] (Run "LoadTextFromFile"): Script operation time: 6 ms
[11:09:22] (Run "LoadTextFromFile"): Script done successfully.
See also
Created with the Personal Edition of HelpNDoc: Easily share your documentation with the world through a beautiful website