Is this true:
"Literal patterns A literal string may be used in a template as a pattern to split up the string. For example parse 'To be, or not to be?' w1 ',' w2 w3 w4 would 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." ??? And, any word on how long the NetRexx stuff will be kept on IBM www pages? Thanks for the help and Enjoy the Day Bob Hamilton Richardson Texas USA _______________________________________________ Ibm-netrexx mailing list [hidden email] Online Archive : http://ibm-netrexx.215625.n3.nabble.com/ |
On 8/17/11 15:26 Robert Hamilton said:
> Is this true: > > "Literal patterns > > A literal string may be used in a template as a pattern to split up > the string. For example > > parse 'To be, or not to be?' w1 ',' w2 w3 w4 > > would 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." ??? Yes Bob, but this is not new to NetRexx; Classic Rexx does it the same way. The template is scanned from left-to-right for a pattern that indicates a point at which to divide the data string. When a pattern is found in the template, the data string is marked at that point. The left part of the string is then word-parsed into the template variables specified to the left of the pattern. This is done as if the left part of the data string, and the variables to the left of the pattern, were the entire string and template in the parse statement. IOW, a blank-delimited word is assigned to each variable from left-to-right. If there are fewer data words than variables, the remaining variables are assigned the null string. If there are more data words than variables, the last variable contains the residual data string. At that point, scanning for patterns continues using the remaining template and the remaining data string. Lather, rinse, and repeat until you run out of data or template. Patterns comes in two flavors, positional and literal. A positional pattern provides the numeric position of a character in the data string; a literal pattern provides the character itself to be found in the data string. Thus, you may parse a string according to specific character positions if you know them, or let Parse find those positions for you. Or both. There are additional ways in which a pattern may be specified, a few more details, and one special case, but that should suffice to explain the following: Parse 'We have met the enemy, and he is us.' w1 9 w2 . ',' . w3 gives w1='We have ' w2='met' w3='he is us.' The first pattern (9) splits off the first 8 characters of the data string, and word-parses that substring into the variable 'w1', because it was the last (only) variable in that subtemplate. The second pattern splits off from the ninth character until the character prior to the next pattern (',') and assigns the first word of that substring into the variable 'w2'. Then, per the placeholder period being the last "variable" on that subtemplate, discards "the enemy". The remaining data string (everything following the comma) is parsed according to the '. w3' subtemplate, which discards the 'and' and places the remaining substring into 'w3'. HTH, -Chip- _______________________________________________ Ibm-netrexx mailing list [hidden email] Online Archive : http://ibm-netrexx.215625.n3.nabble.com/ |
Hello Chip,
*wouldn't it be a GOOD time to publish your *exact* definitions below at a more *prominent place* (say, for instance, nrl4.pdf), or on www.netrexx.org. Bob, one *caveat*, however: You will have to STRIP Leading and Trailing blanks (when there is more as one used in the actual source to be parsed, BY YOUR Own, e.g: x=' this is my string' parse var x a b c d (classic *or* ooRexx) parse x a b c d (NetRexx) a=strip(a) -- oorexx *or* a=a~strip() -- oorexx a=a.strip() -- NetRexx Another way would be to use x=x.space(1), but this will ALSO change spaces in quoted literals. End of lesson from the *beloved* CULPRIT here in Vienna Austria Thomas. ============================================================. Am 17.08.2011 21:05, schrieb Chip Davis: > On 8/17/11 15:26 Robert Hamilton said: >> Is this true: >> >> "Literal patterns >> >> A literal string may be used in a template as a pattern to split up >> the string. For example >> >> parse 'To be, or not to be?' w1 ',' w2 w3 w4 >> >> would 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." ??? > > Yes Bob, but this is not new to NetRexx; Classic Rexx does it the same > way. > > The template is scanned from left-to-right for a pattern that > indicates a point at which to divide the data string. > > When a pattern is found in the template, the data string is marked at > that point. The left part of the string is then word-parsed into the > template variables specified to the left of the pattern. > > This is done as if the left part of the data string, and the variables > to the left of the pattern, were the entire string and template in the > parse statement. IOW, a blank-delimited word is assigned to each > variable from left-to-right. If there are fewer data words than > variables, the remaining variables are assigned the null string. If > there are more data words than variables, the last variable contains > the residual data string. > > At that point, scanning for patterns continues using the remaining > template and the remaining data string. Lather, rinse, and repeat > until you run out of data or template. > > Patterns comes in two flavors, positional and literal. A positional > pattern provides the numeric position of a character in the data > string; a literal pattern provides the character itself to be found in > the data string. > > Thus, you may parse a string according to specific character positions > if you know them, or let Parse find those positions for you. Or both. > > There are additional ways in which a pattern may be specified, a few > more details, and one special case, but that should suffice to explain > the following: > > Parse 'We have met the enemy, and he is us.' w1 9 w2 . ',' . w3 > > gives > > w1='We have ' > w2='met' > w3='he is us.' > > The first pattern (9) splits off the first 8 characters of the data > string, and word-parses that substring into the variable 'w1', because > it was the last (only) variable in that subtemplate. > > The second pattern splits off from the ninth character until the > character prior to the next pattern (',') and assigns the first word > of that substring into the variable 'w2'. Then, per the placeholder > period being the last "variable" on that subtemplate, discards "the > enemy". > > The remaining data string (everything following the comma) is parsed > according to the '. w3' subtemplate, which discards the 'and' and > places the remaining substring into 'w3'. > > HTH, > > -Chip- > _______________________________________________ > Ibm-netrexx mailing list > [hidden email] > Online Archive : http://ibm-netrexx.215625.n3.nabble.com/ > > -- Thomas Schneider (www.thsitc.com) _______________________________________________ Ibm-netrexx mailing list [hidden email] Online Archive : http://ibm-netrexx.215625.n3.nabble.com/
Thomas Schneider, Vienna, Austria (Europe) :-)
www.thsitc.com www.db-123.com |
Free forum by Nabble | Edit this page |