PARSE
The PARSE instruction is particularly powerful; it combines some useful string-handling functions. Its syntax is:
parse [upper] origin template
where origin specifies the source:
- arg (command line variable)
- linein (keyboard)
- pull (REXX data queue)
- source (OS/2 info on how program was executed)
- value (a literal or a function)
- the keyword with required to indicate where the literal ends
- var (a variable)
- version (version/release number)
and template can be:
- list of variables
- column number delimiters
- literal delimiters
upper is optional; it you specify it, data will be converted to upper case.
Examples:
Using a list of variables as template
myVar = "John Smith"
parse var MyVar firstName lastName
say "First name is:" firstName
say "Last name is:" lastName
displays the following
First name is: John
Last name is: Smith
Using a delimiter as template:
myVar = "Smith, John"
parse var MyVar LastName "," FirstName
say "First name is:" firstName
say "Last name is:" lastName
also displays the following
First name is: John
Last name is: Smith
Using column number delimiters:
myVar = "(202) 123-1234"
parse var MyVar 2 AreaCode 5 7 SubNumber
say "Area code is:" AreaCode
say "Subscriber number is:" SubNumber
displays the following
Area code is: 202
Subscriber number is: 123-1234
A template can use a combination of variables, literal delimiters, and column number delimiters.
Under OS/2
REXX is included in the base operating system of OS/2, and is also used as the macro language in many applications.
Under OS/2, a REXX program begins with matched comment delimiters, /* */, to indicate to the operating system that it is a REXX program:
/* sample.cmd */
say "Hello World"
Instructions between quotes are passed to the OS:
/* sample.cmd */
'dir /p /w'
Spelling
In plain text, Cowlishaw seems to prefer Rexx, whereas IBM documents and the majority of the web uses REXX. The ANSI standard uses the form preferred by the standardization committee, which has small capitals for the final three letters: REXX.
External links
redirect
Source | Copyright