quote = 'Knowledge is power.'
PARSE VAR quote word1 word2 word3
/* word1 contains 'Knowledge' */
/* word2 contains 'is' */
/* word3 contains 'power.' */
PARSE VAR does not uppercase character information before assigning it into variables. If you want
uppercase translation, use PARSE UPPER VAR.
More about Parsing into Words
In the preceding examples, the number of words in the data to parse is always the same as the number of
variables in the template. Parsing always assigns new values to all variables named in the template. If
there are more variable names than words in the data to parse, the leftover variables receive null (empty)
values. If there are more words in the data to parse than variable names in the template, each variable
gets one word of data in sequence except the last variable, which gets the remainder of the data.
In the next example, there are more variable names in the template than words of data; the leftover
variable receives a null value.
PARSE VALUE 'Extra variables' WITH word1 word2 word3
/* word1 contains 'Extra' */
/* word2 contains 'variables' */
/* word3 contains '' */
In the next example there are more words in the data than variable names in the template; the last
variable gets the remainder of the data. The last variable name can contain several words and possibly
leading and trailing blanks.
PARSE VALUE 'More words in data' WITH var1 var2 var3
/* var1 contains 'More' */
/* var2 contains 'words' */
/* var3 contains ' in data' */
Parsing into words generally removes leading and trailing blanks from each word before putting it into a
variable. However, when putting data into the last variable, parsing removes one word-separator blank but
retains any extra leading or trailing blanks. There are two leading blanks before words. Parsing removes
both the word-separator blank and the extra leading blank before putting 'words' into var2. There are four
leading blanks before in. Because var3 is the last variable, parsing removes the word-separator blank but
keeps the extra leading blanks. Thus, var3 receives ' in data' (with three leading blanks).
A period in a template acts as a placeholder. It receives no data. You can use a period as a "dummy
variable" within a group of variables or at the end of a template to collect unwanted information.
string='Example of using placeholders to discard junk'
PARSE VAR string var1 . var2 var3 .
/* var1 contains 'Example' */
/* var2 contains 'using' */
/* var3 contains 'placeholders' */
/* The periods collect the words 'of' and 'to discard junk' */
For more information about parsing instructions, see section “PARSE” on page 152.
Parsing with Patterns
The simplest template is a group of blank-separated variable names. This parses data into blank-delimited
words. The preceding examples all use this kind of template. Templates can also contain patterns. A
pattern can be a string, a number, or a variable representing either of these.
Manipulating Data
Chapter 7. Manipulating Data 75