Encoding: CodePage;
Encoding: Prognoz.Platform.Interop.ForeSystem.CodePage;
The Encoding property determines text encoding for reading from a file.
In order text is displayed correctly, the encoding determined by the Encoding property must match with that of the saved file.
Executing the example requires the C:\file.txt text file.
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.ANSI_Cyrillic;
s := TextR.ReadString(10);
End If;
Debug.WriteLine(s);
Dispose File1;
End Sub UserProc;
After executing the example the console window shows the first 10 characters in the ANSI_Cyrillic encoding from the file.txt file.
The requirements and result of the Fore.NET example execution match with those in the Fore example.
Add links to the ForeIO, ForeSystem system assemblies.
Imports Prognoz.Platform.Interop.ForeIO;
Imports Prognoz.Platform.Interop.ForeSystem;
…
Public Shared Sub Main(Params: StartParams);
Var
File1: IFileInfo;
TextR: ITextReader;
s: String;
Begin
File1 := New FileInfo();
File1.Attach("C:\file.txt");
If File1.Exists Then
TextR := File1.OpenTextReader();
TextR.Encoding := CodePage.cpANSI_Cyrillic;
s := TextR.ReadString(10);
End If;
System.Diagnostics.Debug.WriteLine(s);
End Sub;
See also: