Parsing Instructions
The REXX parsing instructions are PULL, ARG, and PARSE. (PARSE has several variants.)
PULL instruction
/* This REXX program parses the string "Knowledge is
power." */
PULL word1 word2 word3
/* word1 contains 'KNOWLEDGE' */
/* word2 contains 'IS' */
/* word3 contains 'POWER.' */
PULL uppercases
character information before assigning it into variables. If you do
not want uppercase translation, use the PARSE PULL instruction.
/* This REXX program parses the string: "Knowledge is
power." */
PARSE PULL word1 word2 word3
/* word1 contains 'Knowledge' */
/* word2 contains 'is' */
/* word3 contains 'power.' */
You can include the optional keyword UPPER on any variant of the PARSE instruction.This causes the language processor to uppercase character information before assigning it into variables. For example, using PARSE UPPER PULL… gives the same result as using PULL.
ARG instruction
- Call the program and pass the arguments as a string following
the exec name:
REXX sample Knowledge is power. - Use the ARG instruction to receive the three arguments into
variables.
/* SAMPLE -- A REXX program using ARG */ ARG word1 word2 word3 /* word1 contains 'KNOWLEDGE' */ /* word2 contains 'IS' */ /* word3 contains 'POWER.' */
ARG uppercases the character information before assigning the arguments into variables.
/* REXX program using PARSE ARG */
PARSE ARG word1 word2 word3
/* word1 contains 'Knowledge' */
/* word2 contains 'is' */
/* word3 contains 'power.' */
PARSE UPPER ARG has the same result as ARG. It uppercases character information before assigning it into variables.
PARSE VALUE … WITH instruction
PARSE VALUE 'Knowledge is power.' WITH word1 word2 word3
/* word1 contains 'Knowledge' */
/* word2 contains 'is' */
/* word3 contains 'power.' */
string='Knowledge is power.'
PARSE VALUE string WITH word1 word2 word3
/* word1 contains 'Knowledge' */
/* word2 contains 'is' */
/* word3 contains 'power.' */
Or you can use
PARSE VAR to parse a variable.
PARSE VAR instruction
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.