This is the legacy 4D documentation web site. Documentations are progressively being moved to developer.4d.com |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
4D v19.8
file.getText( )
|
file.getText ( {charSet}{;}{breakMode} ) -> Result | ||||||||
Parameter | Type | Description | ||||||
charSet | Text, Longint |
![]() |
Name or number of character set | |||||
breakMode | Longint |
![]() |
Processing mode for line breaks | |||||
Result | Text |
![]() |
Text from the document | |||||
The file.getText( ) method returns the contents of the file as text.
The file referenced in the file object must exist on the disk, otherwise an error is generated.
In charSet, pass the character set to be used for reading the contents. You can pass a string containing the standard set name (for example “ISO-8859-1” or “UTF-8”) or its MIBEnum ID (longint). For more information about the list of character sets supported by 4D, refer to the description of the CONVERT FROM TEXT command.
If the document contains a Byte Order Mark (BOM), 4D uses the character set that it has set instead of the one specified in charSet (this parameter is then ignored).
If the document does not contain a BOM and if the charSet parameter is omitted, by default 4D uses the “UTF-8” character sets.
In breakMode, you can pass a longint indicating the processing to apply to end-of-line characters in the document. The following constants of the "System Documents" theme are available:
Constant | Type | Value | Comment |
Document unchanged | Longint | 0 | No processing |
Document with native format | Longint | 1 | (Default) Line breaks are converted to the native format of the operating system: LF (line feed) under macOS, CRLF (carriage return + line feed) under Windows |
Document with CRLF | Longint | 2 | Line breaks are converted to CRLF (carriage return + line feed), the default Windows format. |
Document with CR | Longint | 3 | Line breaks are converted to CR (carriage return), the default Classic Mac OS format. |
Document with LF | Longint | 4 | Line breaks are converted to LF (line feed), the default Unix and macOS format. |
By default, when you omit the breakMode parameter, line breaks are processed in native mode (1).
Returned value
Text of the file.
Given the following text document (fields are separated by tabs):
id name price vat
3 thé 1.06€ 19.6
2 café 1.05€ 19.6
When you execute this code:
$myFile:=Folder(fk documents folder).file("Billing.txt") //UTF-8 by default
$txt:=$myFile.getText()
... you get:
// $Text = "id name price vat\r\n3 thé 1.06€\t19.6\r\n2\tcafé\t1.05€\t19.6"
// \t = tab
// \r = CR
Product: 4D
Theme: File and Folder
Created: 4D v17 R5
4D Language Reference ( 4D v19)
4D Language Reference ( 4D v19.1)
4D Language Reference ( 4D v19.4)
4D Language Reference ( 4D v19.5)
4D Language Reference ( 4D v19.6)
4D Language Reference ( 4D v19.7)
4D Language Reference ( 4D v19.8)