Programmer Guide/Command Reference/READ: Difference between revisions

From STX Wiki
Jump to navigationJump to search
m (1 revision: Initial import)
No edit summary
 
(5 intermediate revisions by 2 users not shown)
Line 1: Line 1:
{{DISPLAYTITLE:{{SUBPAGENAME}}}}
{{DISPLAYTITLE:{{SUBPAGENAME}}}}
==READ==
READ <var>file</var> <var>varseplist</var> [ /Delete ] [ /Noparsing ] [ /Escape[=<var>escapechar</var>] ] [ [[Programmer_Guide/Command_Reference_Options/Silent|/Silent]] ] [ /R=<var>x</var> ] [ /Trimmenot ]
READSTR <var>string</var> <var>varseplist</var> [ /Delete ] [ /Noparsing ] [ /Escape[=<var>escapechar</var>] ] [ [[Programmer_Guide/Command_Reference_Options/Silent|/Silent]] ][ /R=<var>x</var> ] [ /Trimmenot ]
READVAR <var>var</var> <var>varseplist</var> [ /Delete ] [ /Noparsing ] [ /Escape[=<var>escapechar</var>] ] [ [[Programmer_Guide/Command_Reference_Options/Silent|/Silent]] ] [ /R=<var>x</var> ] [ /Trimmenot ]
READTAB <var>table</var> <var>iEntry</var> <var>varseplist</var> [ /Delete ] [ /Noparsing ] [ /Escape[=<var>escapechar</var>] ] [ [[Programmer_Guide/Command_Reference_Options/Silent|/Silent]] ] [ /Trimmenot ]
READTAB <var>table</var> <var>iField</var> <var>varseplist</var> /Config [ /Delete ] [ /Noparsing ] [ /Escape[=<var>escapechar</var>] ] [ [[Programmer_Guide/Command_Reference_Options/Silent|/Silent]] ] [ /Trimmenot ]
READTAB <var>table</var> <var>iEntry</var> <var>iField</var> <var>varseplist</var> /Field [ /Delete ] [ /Noparsing ] [ /Escape[=<var>escapechar</var>] ] [ [[Programmer_Guide/Command_Reference_Options/Silent|/Silent]] ] [ /Trimmenot ]


<code>READ <var>file varseplist</var> [/D] [ /N ] [ /E[=<var>escapeseq</var>] ] [ /S ] [ /R=<var>x</var> ]</code>
The <code>READ</code> command and its variants <code>READSTR</code>, <code>READTAB</code> and <code>READVAR</code> parse data into variables:


<code>READSTR <var>string varseplist</var> [/D] [ /N ] [ /E[=<var>escapeseq</var>] ] [ /S ][ /R=<var>x</var> ]</code>
* The <code>READ</code> command parses the next line of an input file <var>file</var>, replacing the linefeed character (<code>\n</code>) with a string terminator (<code>\0</code>).
* The <code>READSTR</code> command interprets the first parameter as a string, parsing it into the other parameters.
* The <code>READVAR</code> command interprets the first parameter as a variable name, parsing the contents of the respective variable into the other parameters.
* The <code>READTAB</code> command takes a table name and entry index as the first two parameters, and parses the contents of the respective table entry into the remaining parameters.


<code>READVAR <var>var varseplist</var> [/D] [ /N ] [ /E[=<var>escapeseq</var>] ] [ /S ] [ /R=<var>x</var> ]</code>
The parameter <var>varsepplist</var> is a list of variables to assign values to, and of separators to parse the input with. For example, the following command reads an input string into three variables, using the default separator (the blank):


<code>READTAB <var>table iEntry varseplist</var> [/D] [ /N ] [ /E[=<var>escapeseq</var>] ] [ /S ]</code>
READSTR 'a b c' #1 #2 #3
// #1 := a, #2 := b, #3 := c, #READ := 3


<code>READTAB <var>table iField varseplist</var> /C [/D] [ /N ] [ /E[=<var>escapeseq</var>] ] [ /S ]</code>
If separators are specified, the string is tokenised accordingly:


<code>READTAB <var>table iEntry iField varseplist</var> /F [/D] [ /N ] [ /E[=<var>escapeseq</var>] ] [ /S ]</code>
#var := set '10/8/2008 19:14'
READVAR #var #day'/'#month'/'#year' '#hour':'#minute


The <code>READ</code> command and its variants (<code>READSTR</code>, <code>READTAB</code> and <code>READVAR</code>) can be used to parse input into variables.
If there are more tokens than variables, all remaining tokens are stored in the last variable:


The <code>READ</code> command parses the next line of the input file <var>file</var>, replacing the linefeed character (<code>\n</code>) with a string terminator (<code>\0</code>).
#var := set 'the big brown fox'
READVAR #var #1 #2 #3
// #1 := the,  #2 := big, #3 := brown fox, #READ := 3


The <code>READSTR</code> command interprets the first parameter as a string, parsing it into the other parameters.
The number of variables to which tokens were assigned is stored in the local variable <var>#READ</var>.


The <code>READVAR</code> command interprets the first parameter as a variable name, parsing it into the other parameters.
READSTR '' #1 #2
 
  // #READ := 0
The <code>READTAB</code> 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.
READSTR 'a' #1 #2
 
// #READ := 1
The parameter <var>varsepplist</var> 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
 
// #READ := 2
<pre>
READSTR 'a b c' #1 #2 #3
// #1 := a, #2 := b, #3 := c, #READ := 3
</pre>
If separators are specified, the string is tokenised accordingly.
 
<pre>
#var := set '10/8/2008 19:14'
READVAR #var #day'/'#month'/'#year' '#hour':'#minute
</pre>
If there are more tokens than variables, all remaining tokens are stored in the last variable.
 
<pre>
#var := set 'the big brown fox'
READVAR #var #1 #2 #3
// #1 := the, #2 := big, #3 := brown fox, #READ := 3
</pre>
The number of variables to which tokens were assigned is stored in the local variable <code>#READ</code>.
 
<pre>
READSTR '' #1 #2
// #READ := 0
READSTR 'a' #1 #2
// #READ := 1
READSTR 'a b c' #1 #2
// #READ := 2
</pre>
;<var>/N</var>


;<code>/Noparsing</code>
:If specified, no parsing, stripping or escape character handling takes place. The contents of the first argument are assigned to the second argument.
:If specified, no parsing, stripping or escape character handling takes place. The contents of the first argument are assigned to the second argument.


;<var>/D</var>
;<code>/Delete</code>
 
:If specified, the contents (if any) of the variables specified in <var>varseplist</var> are deleted before parsing.
:If specified, the contents (if any) of the variables specified in <var>varseplist</var> are deleted before parsing.


;<var>/E</var>
;<code>/Escape=<var>escapechar</var></code>
:You can define an escape character of your own using the <code>/Escape</code> option. E.g. defining "<code>\</code>" as the escape character by supplying <code>/Escape=\</code> will change parsing as follows:


:You can define an escape character using the /E option. E.g. defining '<code>\</code>' as the escape character will change parsing as follows:
READSTR 'a b \, c' #a','#b /D
 
// #a := a b \
<pre>
// #b := c
READSTR 'a b \, c' #a','#b /D
// #READ := 2
// #a := a b \
READSTR 'a b \, c' #a','#b /D /E=\
// #b := c
// #a := a b \, c
// #READ := 2
// #b :=  
READSTR 'a b \, c' #a','#b /D /E=\
// #READ := 1
// #a := a b \, c
:The default escape character is the back-tick character, "<code>`</code>"
// #b :=  
// #READ := 1
</pre>
:The default escape character is '<code>`</code>'
 
;<var>/C</var>


;<code>/Config</code>
:If specified, the contents of the table field's configuration is used as the input.
:If specified, the contents of the table field's configuration is used as the input.


;<var>/F</var>
;<code>/Field</code>
 
:If specified, the contents of the addressed entry field is used as the input.
:If specified, the contents of the addressed entry field is used as the input.


;<var>/S</var>
;<code>[[Programmer_Guide/Command_Reference_Options/Silent|/Silent]]</code>
 
:If specified, errors will generate warning messages rather than error messages. See [[Programmer_Guide/Command_Reference_Options/Silent|The Silent Flag]] for details.
:If specified, errors will generate warning messages rather than error messages. See The Silent Flag for details.
 
;<var>/T</var>


;<code>/Trimmenot</code>
:If specified, arguments will *not* have their left and right white space trimmed. The default is that they are trimmed.
:If specified, arguments will *not* have their left and right white space trimmed. The default is that they are trimmed.


For more <code>READ</code> examples, see the <code>read_example.sts</code> script.
For more <code>READ</code> examples, see the <code>read_example.sts</code> script.
See also [[../WRITE|WRITE]].

Latest revision as of 13:20, 13 August 2018

READ file varseplist [ /Delete ] [ /Noparsing ] [ /Escape[=escapechar] ] [ /Silent ] [ /R=x ] [ /Trimmenot ]

READSTR string varseplist [ /Delete ] [ /Noparsing ] [ /Escape[=escapechar] ] [ /Silent ][ /R=x ] [ /Trimmenot ]

READVAR var varseplist [ /Delete ] [ /Noparsing ] [ /Escape[=escapechar] ] [ /Silent ] [ /R=x ] [ /Trimmenot ]

READTAB table iEntry varseplist [ /Delete ] [ /Noparsing ] [ /Escape[=escapechar] ] [ /Silent ] [ /Trimmenot ]

READTAB table iField varseplist /Config [ /Delete ] [ /Noparsing ] [ /Escape[=escapechar] ] [ /Silent ] [ /Trimmenot ]

READTAB table iEntry iField varseplist /Field [ /Delete ] [ /Noparsing ] [ /Escape[=escapechar] ] [ /Silent ] [ /Trimmenot ]

The READ command and its variants READSTR, READTAB and READVAR parse data into variables:

  • The READ command parses the next line of an 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 the contents of the respective variable into the other parameters.
  • The READTAB command takes a table name and entry index as the first two parameters, and parses the contents of the respective table entry into the remaining parameters.

The parameter varsepplist is a list of variables to assign values to, and of separators to parse the input with. For example, the following 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
/Noparsing
If specified, no parsing, stripping or escape character handling takes place. The contents of the first argument are assigned to the second argument.
/Delete
If specified, the contents (if any) of the variables specified in varseplist are deleted before parsing.
/Escape=escapechar
You can define an escape character of your own using the /Escape option. E.g. defining "\" as the escape character by supplying /Escape=\ 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 the back-tick character, "`"
/Config
If specified, the contents of the table field's configuration is used as the input.
/Field
If specified, the contents of the addressed entry field is used as the input.
/Silent
If specified, errors will generate warning messages rather than error messages. See The Silent Flag for details.
/Trimmenot
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.

See also WRITE.

Navigation menu

Personal tools