NetRexx Overview, version 2.02
Copyright (c) IBM Corporation, 2001. All rights reserved. ©
|22 May 2001|
|[previous | contents | next]|
A parse instruction first specifies the string to be parsed. This can be any term, but is often taken simply from a variable. The term 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.
The NetRexx Language by