NetRexx Overview, version 1.142
Copyright (c) IBM Corporation, 1998. All rights reserved. © | 1 Sep 1998 |
[previous | contents | next] |
A parse instruction first specifies the string to be parsed, often taken simply from a variable. This is followed by a template which describes how the string is to be split up, and where the pieces are to be put.
parse 'This is a sentence.' v1 v2 v3the variable v1 would be assigned the value 'This', v2 would be assigned the value 'is', and v3 would be assigned the value 'a sentence.'.
parse 'To be, or not to be?' w1 ',' w2 w3 w4would cause the string to be scanned for the comma, and then split at that point; each section is then treated in just the same way as the whole string was in the previous example.
Thus, w1 would be set to 'To be', w2 and w3 would be assigned the values 'or' and 'not', and w4 would be assigned the remainder: 'to be?'. Note that the pattern itself is not assigned to any variable.
The pattern may be specified as a variable, by putting the variable name in parentheses. The following instructions:
comma=',' parse 'To be, or not to be?' w1 (comma) w2 w3 w4therefore have the same effect as the previous example.
From
The NetRexx Language by
Mike Cowlishaw,