$Word

From m204wiki
Revision as of 18:57, 31 July 2014 by Mlarocca (talk | contribs) (Mlarocca moved page $WORD to $Word: Lower case change)
Jump to navigation Jump to search

The $WORD function searches a string from the left for a complete word and returns the nth word in a specified string, delimited by a blank or optionally specified character.

Syntax

The format of the $WORD function is:

$WORD('inputstring',['delimiter'],[n])

where:

  • inputstring is the input from which the specified word is to be extracted. inputstring can be a quoted literal or a %variable.
  • delimiter is an optional quoted character or string to be used as a delimiter in parsing the input string into words. If delimiter is not specified, it defaults to a blank space. If delimiter consists of more than one character, Model 204 uses the first character in the string as the delimiter.
  • n is the ordinal number of the word to be extracted. $WORD returns a null string under any of the following conditions:

n is not specified

n is less than 1 (0 or negative)

n is greater than the number of words in inputstring

The commas which separate the three arguments are required, even if delimiter is not specified.

Usage

Null values between delimiters are not considered words. For example,

$WORD('=ABCD==D=XXX','=',2)

returns D as the second word, not a null value.

Examples

The following function returns the third word in the string, "THE", when a single space delimits a word:

$WORD ('NOW IS THE TIME',,3)

The following function returns the second word in the string, "S THE T", where a word is composed of the characters that precede a delimiting I:

$WORD ('NOW IS THE TIME','I',2)