Saves a string (text) as a file or registry value or reads a text from a file or the registry.
s = Client.LoadText (Location [, Options])
Client.SaveText(s, Location [, Options])
File name or registry value incl. path. For registry values, the prefix "registry://" must be specified.
Example for file specification:
Example for Registry:
options: variant [optional]
Charset specification or options string.
In order to be able to distinguish the different Unicode memory formats UTF-8, UTF-16 and UTF-16BE from each other and from normal Ansi files, the Unicode standard provides for a so-called Byte-Order-Mark (BOM) to be written at the beginning of the file. This can sometimes lead to problems with further processing on Unix systems. It is also unusual with UTF-8 encoded web pages and leads to display problems in the browser. In these cases WriteBOM can be set to "0".
|"TRUE"||for SaveText only: If Overwrite is set to False, an error message is displayed if the file already exists. Otherwise it is overwritten.
If Append is TRUE, Overwrite is not evaluated
|"FALSE"||for LoadText only: If CheckExists is set to True, an error message is displayed. If the file or registry value is set to "FALSE", an empty string is returned.|
|"FALSE"||If the file already exists, the text is appended to the file. This option is only available for files.
When attaching to an existing file, make sure to use the same charset setting as the original file. There is no automatic recognition of the available data!
No automatic interlace is added when appending. In VBScript this can be done with the constant vbCrLf (see example B)
A. Saving a text with different character sets.
The following script creates a three-line text that contains Chinese characters as well as umlauts. This text is then saved to the desktop in different character sets. After the script there is a screen with the hexadecimal representations of the individual files. Note: The sample text displayed must be copied directly into the iScript editor. When saving in the editor, the special characters are lost because the registry is currently not yet Unicode-compatible.
VBScript dim sl, s, desktop set sl = client.NewStrings sl.Add "Umlaute: öäüÖÄÜ und ß" sl.Add "chinese: 系统正在测试中" sl.Add "ENDE" desktop = client.properties("folder.desktop") & "\" s = sl.Text Client.SaveText s, Desktop & "SaveText_Ansi.txt" Client.SaveText s, Desktop & "SaveText (MS-DOS).txt", "ibm437" Client.SaveText s, Desktop & "SaveText (UTF-8 mit BOM).txt", "utf-8" Client.SaveText s, Desktop & "SaveText (UTF-16 mit BOM).txt", "utf-16" Client.SaveText s, Desktop & "SaveText (UTF-16BE mit BOM).txt", "utf-16BE" ' if something other than "charset" is to be specified, then
' the options are qualified by name Client.SaveText s, Desktop & "SaveText (UTF8 ohne BOM).txt", _ "charset=utf-8;writebom=0"
Hex representation of the different character sets:
B. Attach to a file
dim i, filename filename = client.properties("folder.desktop") & "\SaveText_Append.txt" options = "charset=utf-8;append=1" ' Numbers are written one after the other in one line for i = 1 to 9 Client.SaveText CStr(i), Filename, options next ' Appending line by line using vbCrLf for i = 1 to 9 Client.SaveText " - Zeile " & CStr(i) & vbCrLf, Filename, options next