This is the legacy 4D documentation web site. Documentations are progressively being moved to developer.4d.com |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
4D v19.8
file.setText( )
|
file.setText ( text {; charSet {; breakMode}} ) | ||||||||
Parameter | Type | Description | ||||||
text | Text |
![]() |
Text to store in the file | |||||
charSet | Text, Longint |
![]() |
Name or number of character set | |||||
breakMode | Longint |
![]() |
Processing mode for line breaks | |||||
The file.setText( ) method writes text as the new contents of the file.
If the file referenced in the File object does not exist on the disk, it is created by the method. When the file already exists on the disk, its prior contents are erased, except if it is already open, in which case, its contents are locked and an error is generated.
In text, pass the text to write to the file. It can be a literal ("my text"), or a 4D text field or variable.
In charSet, pass the character set to be used for writing the contents. You can pass a string containing the standard character 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 a Byte Order Mark (BOM) exists for the character set, 4D inserts it into the file. If you do not specify a character set, by default 4D uses the "UTF-8" character set without BOM (except in compatibility mode, see Compatibility page).
In breakMode, you can pass a longint indicating the processing to apply to end-of-line characters before saving them in the file. The following constants, found in 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).
$myFile:=File("C:\\Documents\\Hello.txt";fk platform path)
$myFile.setText("Hello world")
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)