READ

From STX Wiki
Jump to navigationJump to search
READ file varseplist [/D] [ /N ] [ /E[=escapeseq] ] [ /S ] [ /R=x ]

READSTR string varseplist [/D] [ /N ] [ /E[=escapeseq] ] [ /S ][ /R=x ]

READVAR var varseplist [/D] [ /N ] [ /E[=escapeseq] ] [ /S ] [ /R=x ]

READTAB table iEntry varseplist [/D] [ /N ] [ /E[=escapeseq] ] [ /S ]

READTAB table iField varseplist /C [/D] [ /N ] [ /E[=escapeseq] ] [ /S ]

READTAB table iEntry iField varseplist /F [/D] [ /N ] [ /E[=escapeseq] ] [ /S ]

The READ command and its variants (READSTR, READTAB and READVAR) can be used to parse input into variables.

The READ command parses the next line of the input file file, replacing the linefeed character (\n) with a string terminator (\0).

The READSTR command interprets the first parameter as a string, parsing it into the other parameters.

The READVAR command interprets the first parameter as a variable name, parsing it into the other parameters.

The READTAB command takes a table name and entry index as the first two parameters, and parses the contents of table entry specified by the index into the remaining parameters.

The parameter varsepplist is a list of variables to assign values to and separators to parse the input with. For example, this command reads an input string into three variables, using the default separator (the blank).

READSTR 'a b c' #1 #2 #3
// #1 := a, #2 := b, #3 := c, #READ := 3

If separators are specified, the string is tokenised accordingly.

#var := set '10/8/2008 19:14'
READVAR #var #day'/'#month'/'#year' '#hour':'#minute

If there are more tokens than variables, all remaining tokens are stored in the last variable.

#var := set 'the big brown fox'
READVAR #var #1 #2 #3
// #1 := the,  #2 := big, #3 := brown fox, #READ := 3

The number of variables to which tokens were assigned is stored in the local variable #READ.

READSTR '' #1 #2
// #READ := 0
READSTR 'a' #1 #2
// #READ := 1
READSTR 'a b c' #1 #2
// #READ := 2
/N
If specified, no parsing, stripping or escape character handling takes place. The contents of the first argument are assigned to the second argument.
/D
If specified, the contents (if any) of the variables specified in varseplist are deleted before parsing.
/E
You can define an escape character using the /E option. E.g. defining '\' as the escape character will change parsing as follows:
READSTR 'a b \, c' #a','#b /D
// #a := a b \
// #b := c
// #READ := 2
READSTR 'a b \, c' #a','#b /D /E=\
// #a := a b \, c
// #b := 
// #READ := 1
The default escape character is '`'
/C
If specified, the contents of the table field's configuration is used as the input.
/F
If specified, the contents of the addressed entry field is used as the input.
/S
If specified, errors will generate warning messages rather than error messages. See The Silent Flag for details.
/T
If specified, arguments will *not* have their left and right white space trimmed. The default is that they are trimmed.

For more READ examples, see the read_example.sts script.

Navigation menu

Personal tools