Combining Patterns and Parsing Into Words

About this task

What happens when a template contains patterns that divide the source string into sections containing multiple words? String and positional patterns divide the source string into substrings. The language processor then applies a section of the template to each substring, following the rules for parsing into words.
/* Combining string pattern and parsing into words               */
name='    John      Q.   Public'
parse var name fn init '.' ln        /* Assigns: fn='John'       */
                                     /*          init='     Q'   */
                                     /*          ln='   Public'  */
The pattern divides the template into two sections:
  • fn init
  • ln
The matching pattern splits the source string into two substrings:
  • ' John Q'
  • ' Public'
The language processor parses these substrings into words based on the appropriate template section.

John had three leading blanks. All are removed because parsing into words removes leading and trailing blanks except from the last variable.

Q has six leading blanks. Parsing removes one word-separator blank and keeps the rest because init is the last variable in that section of the template.

For the substring ' Public', parsing assigns the entire string into ln without removing any blanks. This is because ln is the only variable in this section of the template. (For details about treatment of blanks, see Simple Templates for Parsing into Words.)
/* Combining positional patterns with parsing into words         */
string='R E X X'
parse var string var1 var2 4 var3 6 var4   /* Assigns: var1='R'  */
                                           /*          var2='E'  */
                                           /*          var3=' X' */
                                           /*          var4=' X' */
The pattern divides the template into three sections:
  • var1 var2
  • var3
  • var4
The matching patterns split the source string into three substrings that are individually parsed into words:
  • 'R E'
  • ' X'
  • ' X'
The variable var1 receives 'R'; var2 receives 'E'. Both var3 and var4 receive ' X' (with a blank before the X) because each is the only variable in its section of the template. (For details on treatment of blanks, see Simple Templates for Parsing into Words.)

Task Task

Feedback


Timestamp icon Last updated: Tuesday, 7 January 2014


http://pic.dhe.ibm.com/infocenter/cicsts/v5r1/topic/com.ibm.cics.rexx.doc//dfhrx/patwd.html