Programmer Guide/Command Reference/KEYWORD: Difference between revisions
(initial import) |
|||
(18 intermediate revisions by 3 users not shown) | |||
Line 1: | Line 1: | ||
{{DISPLAYTITLE:{{SUBPAGENAME}}}} | {{DISPLAYTITLE:{{SUBPAGENAME}}}} | ||
== | {{PG_StringCommands}} | ||
In its first form, the {{STX}} command <code>KEYWORD</code> searches for a keyword, or for the (non-unique) abbreviation of a keyword, in a list of keywords. In its second form, it simply checks a list of keywords for the presence of a keyword with a given index. | |||
__TOC__ | |||
== Searching for a keyword or its abbreviation == | |||
<code><var>var</var> | The <code>KEYWORD</code> command searches for a keyword, or for the (non-unique) abbreviation of a keyword, in a list of keywords. It is supplied a single string <var>testValue</var> (the keyword to search, or its abbreviation), and a list of blank-separated keyword arguments, <var>keyword<sub>0</sub></var> [ … <var>keyword<sub>n</sub></var> ]. The command returns the zero-based index of the first keyword in <var>keyword<sub>0</sub></var> [ … <var>keyword<sub>n</sub></var> ] equal to (if option <code>/Full</code> is supplied), or starting with, <var>testValue</var>. If <var>keyword<sub>0</sub></var> [ … <var>keyword<sub>n</sub></var> ] does not contain an appropriate keyword, the command will return -1. | ||
-> var | <var>var</var> := KEYWORD [ /Full [ /Casesensitive ] ] [[Programmer_Guide/Command_Reference_Options/-|/-]] <var>testValue</var> <var>keyword<sub>0</sub></var> [ … <var>keyword<sub>n</sub></var> ] | ||
;<var>testValue</var> | ;<var>testValue</var>: the keyword to locate in <var>keywordList</var>, or its abbreviation. Note that the <code>KEYWORD</code> command does not expect a unique abbreviation - it will simply return the first keyword starting with <code>testValue</code>, even if there are dozens more. Note also, that if this value is an integer, it is interpreted as a zero-based index, making the command synonymous with the [[Programmer_Guide/Command_Reference/WORD|<code>WORD</code>]] command. | ||
;<var>keyword<sub>0</sub></var> [ … <var>keyword<sub>n</sub></var> ]: a blank-separated list of keywords | |||
;<code>/Full</code>: if specified, the function searches for the first entry exactly equal to <var>testValue</var>, meaning that abbreviations will not be found. | |||
;<code>/Casesensitive</code>: If used in conjunction with <code>/Full</code>, the comparison is case sensitive. Without <code>/Full</code>, this option will be ignored and will have no effect whatsoever. | |||
See also the fine [[Programmer_Guide/Command_Reference/WORD|<code>WORD</code>]] command. | |||
=== Examples === | |||
: | // will return 0, because "toll" starts with "to" | ||
#index := keyword /- to toll too to Toledo | |||
// will return 2, because "/Full" looks for strict equality | |||
#index := keyword /Full /- to toll too to Toledo | |||
// will return 3, because "tofu" starts with "to" | |||
// note that "alas toll" is ''one'' argument | |||
#index := keyword /- to 'alas toll' fine backyard tofu | |||
// will return 1, because "toll" starts with "to" | |||
// note compare this with the previous example | |||
#index := keyword /- to alas toll fine backyard tofu | |||
// will return -1, because the keyword list does not contain "To" | |||
#index := keyword /Full /Casesensitive /- To toll too to Toledo | |||
// will return '''0''', because "/Casesensitive" is valid only with "/Full", | |||
// and so it is ignored here! | |||
#index := keyword /Casesensitive /- To toll too to Toledo | |||
== Checking for the presence of an index == | |||
Instead of a keyword, or its abbreviation, the <code>KEYWORD</code> command may be supplied an integer. It will then check if this integer is a valid index in the respective keyword list. If this is the case, it will return the unmodified index. Otherwise, it will return -1. | |||
;<var>/ | <var>var</var> := KEYWORD <var>index</var> <var>keyword<sub>0</sub></var> [ … <var>keyword<sub>n</sub></var> ] | ||
=== Examples === | |||
// will return 2, simply because there ''is'' a keyword with index 2 | |||
#index := KEYWORD 2 a b c d | |||
// will return -1, because there is no keyword with index 17 | |||
// (there are only four keywords, meaning that indexes will | |||
// range from 0 to 3, only) | |||
#index := KEYWORD 17 a b c d |
Latest revision as of 11:34, 15 November 2016
In its first form, the STx command KEYWORD
searches for a keyword, or for the (non-unique) abbreviation of a keyword, in a list of keywords. In its second form, it simply checks a list of keywords for the presence of a keyword with a given index.
Contents
Searching for a keyword or its abbreviation
The KEYWORD
command searches for a keyword, or for the (non-unique) abbreviation of a keyword, in a list of keywords. It is supplied a single string testValue (the keyword to search, or its abbreviation), and a list of blank-separated keyword arguments, keyword0 [ … keywordn ]. The command returns the zero-based index of the first keyword in keyword0 [ … keywordn ] equal to (if option /Full
is supplied), or starting with, testValue. If keyword0 [ … keywordn ] does not contain an appropriate keyword, the command will return -1.
var := KEYWORD [ /Full [ /Casesensitive ] ] /- testValue keyword0 [ … keywordn ]
- testValue
- the keyword to locate in keywordList, or its abbreviation. Note that the
KEYWORD
command does not expect a unique abbreviation - it will simply return the first keyword starting withtestValue
, even if there are dozens more. Note also, that if this value is an integer, it is interpreted as a zero-based index, making the command synonymous with theWORD
command. - keyword0 [ … keywordn ]
- a blank-separated list of keywords
/Full
- if specified, the function searches for the first entry exactly equal to testValue, meaning that abbreviations will not be found.
/Casesensitive
- If used in conjunction with
/Full
, the comparison is case sensitive. Without/Full
, this option will be ignored and will have no effect whatsoever.
See also the fine WORD
command.
Examples
// will return 0, because "toll" starts with "to" #index := keyword /- to toll too to Toledo // will return 2, because "/Full" looks for strict equality #index := keyword /Full /- to toll too to Toledo // will return 3, because "tofu" starts with "to" // note that "alas toll" is one argument #index := keyword /- to 'alas toll' fine backyard tofu // will return 1, because "toll" starts with "to" // note compare this with the previous example #index := keyword /- to alas toll fine backyard tofu // will return -1, because the keyword list does not contain "To" #index := keyword /Full /Casesensitive /- To toll too to Toledo // will return 0, because "/Casesensitive" is valid only with "/Full", // and so it is ignored here! #index := keyword /Casesensitive /- To toll too to Toledo
Checking for the presence of an index
Instead of a keyword, or its abbreviation, the KEYWORD
command may be supplied an integer. It will then check if this integer is a valid index in the respective keyword list. If this is the case, it will return the unmodified index. Otherwise, it will return -1.
var := KEYWORD index keyword0 [ … keywordn ]
Examples
// will return 2, simply because there is a keyword with index 2 #index := KEYWORD 2 a b c d // will return -1, because there is no keyword with index 17 // (there are only four keywords, meaning that indexes will // range from 0 to 3, only) #index := KEYWORD 17 a b c d