ITextReader.Encoding

Syntax

Encoding: CodePage;

Description

The Encoding property determines a text encoding to read from a file.

Comments

In order text is displayed correctly, the encoding determined by the Encoding property must match with that of the saved file. By default, the Encoding property uses the encoding used during operating system installation.

Example

Executing the example requires the text file: C:\file.txt. The file has the UTF-8 encoding.

Add a link to the IO system assembly.

Sub UserProc;
Var
    File1: IFileInfo;
    TextR: ITextReader;
    s: String;
Begin
    File1 := New FileInfo.Attach("C:\file.txt");
    If File1.Exists Then
        TextR := File1.OpenTextReader;
        TextR.Encoding := CodePage.UTF8;
        s := TextR.ReadString(10);
    End If;
    Debug.WriteLine(s);
    Dispose File1;
End Sub UserProc;

After executing the example the first ten characters are read from the file. The obtained value is displayed in the development environment console.

See also:

ITextReader