/
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.

CastDescription
"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

NameTypeRequiredComments
string 2String or string arrayNoCommand can accept any number of strings/arrays to write to the file
string 1String or string arrayNo1 or more string to be written to the file
fileIDint
ID of file previously opened with fileOpen

Flags

NameFlag argumentsArgument typeExclusive toComments
cast1stringData type to cast to. Possible types are listed above. Note that data can be lost when casting.
length1integerLength 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