Main Help → All Commands → Language Reference → Words
The Words
command divides up a variable by words:
Words "(varName)",(start),(end),(expr),<(split)>
where:
"(varName)"
is a valid string variable name in quotes (e.g., "#varName$"), but not an array name followed by [(index)]
.(start)
and (end)
specify the range of words to extract (first word is word number 1) or can be <=0 to specify word number relative to the end (0 is last word, -1 is next to last word, etc.).(expr)
is a string or string expression possibly containing multiple words.(split)
is optional string. When used, words are defined by splitting (expr)
at occurrences of the provided string. When omitted, words are defined by whitespace.When done, the result will be in the specified variable.
If the qouted variable name is "#varName"
, for example, the extracted words will be in #varName[1]
, #varName[2]
, etc., and the total number of words will be stored in #varName[0]
.
(split)=" "
) is not the same as omitting (split)
to split at white space. The former will count every space as a delimiter and words between adjacent spaces will the zero-length strings. In contrast, splitting at whitespace considers multiple spaces as a single word delimiter.