Vicon Shogun banner

Description

Use to read a string from a file. Command will fail if at the end of the file.

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 value will always be positive.

Casting doesn't make sense when reading strings, but the option is still there for you.

CastDescription
cReads each string character as a signed character, or signed 8-bit (1 byte) value
ucReads each string character as an unsigned character, or unsigned 8-bit (1 byte) value
sReads each string character as a signed short integer, or signed 16-bit (2 bytes) value
usReads each string character as an unsigned short integer, or unsigned 16-bit (2 bytes) value
iReads each string character as a signed integer, or signed 32-bit (4 bytes) value
uiReads each string character as an unsigned integer, or unsigned 32-bit (4 bytes) value
fReads each string character as a floating point value, or a 32-bit (4 byte) value

Functional area

Disk I/O

Command syntax

Syntax

readString fileID length [-cast string]

Arguments

NameTypeRequiredComments
lengthint
Length of the string to read from the file. Must be a positive value.
Will read in characters up to the newline character, or length, whichever comes first.
Will not return the newline character. Maximum value is 1024
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.

Return value

string

Examples

string $str; 
int $length;
int $fileID;
int $fileID = `fileOpen "C:/FileTesting.txt" "r"`;
// First read the string length
$length = `readInt $fileID` + 1;
// Now read the string
$str = `readString $fileID $length`;
fileClose $fileID; //close the file
// Print out the value
print $str;

Additional information

Related commands