/
writeString
writeString
Description
Use to write one or more strings to a file. This command accepts any number of string arguments, including arrays.
The following is a listing of the different cast types. Note that data can be lost when casting. 'Signed' means the value can be negative. 'Unsigned' means the value is always positive.
Casting doesn't make sense when writing strings, but the option is still there for you.
Cast | Description |
---|---|
"c" | Writes each string character as a signed character, or a signed 8 bit (1 byte) value |
"uc" | Writes each string character as an unsigned character, or an unsigned 8 bit (1 byte) value |
"s" | Writes each string character as a signed short integer, or a signed 16 bit (2 bytes) value |
"us" | Writes each string character as an unsigned short integer, or an unsigned 16 bit (2 bytes) value |
"i" | Writes each string character as a signed integer, or a signed 32 bit (4 bytes) value |
"ui" | Writes each string character as an unsigned integer, or an unsigned 32 bit (4 bytes) value |
"f" | Writes each string character as a floating point value, a 32 bit (4 byte) value |
Functional area
Disk I/O
Command syntax
Syntax
writeString fileID stringVal1 [stringVal2...] [-cast string] [-length integer] |
Arguments
Name | Type | Required | Comments |
---|---|---|---|
string 2 | String or string array | No | Command can accept any number of strings/arrays to write to the file |
string 1 | String or string array | No | 1 or more string to be written to the file |
fileID | int | ID of file previously opened with fileOpen |
Flags
Name | Flag arguments | Argument type | Exclusive to | Comments |
---|---|---|---|---|
cast | 1 | string | — | Data type to cast to. Possible types are listed above. Note that data can be lost when casting. |
length | 1 | integer | — | Length of the string to write. Strings are usually written out at a fixed length, or prepended with the length of the string if the string length is variable. If you want to write out a fixed length string, use this flag. Max length is 1024 |
Return value
void
Examples
//Write example string $str = "This is some text"; int $length; int $fileID; int $fileID = `fileOpen "C:/FileTesting.txt" "w"`; // Get the string length $length = `strLength $str`; // First write out the string length writeInt $fileID $length; // Then write the string writeString $fileID $str; fileClose $fileID;
Additional information
Related commands
, multiple selections available,