/* Combining string pattern and parsing into words */
name=" John Q. Public"
parse var name fn init "." ln /* Assigns: fn="John" */
/* init=" Q" */
/* ln=" Public" */
fn initln
" John Q"
" Public"
John has 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." 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 whitespace characters, see
Section 9.1, “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" */
var1 var2var3var4"R E"" X"" X"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 whitespace
characters, see
Section 9.1, “Simple Templates for Parsing into Words”.)