-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvgettoken.hlp
108 lines (82 loc) · 5.21 KB
/
vgettoken.hlp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
{smcl}
{hline}
help for {hi:vgettoken}{right: Bill Rising}
{hline}
{hi:Pull the First Token from Each Observation of a Variable}
{* put the syntax in what follows. Don't forget to use [ ] around optional items}
{p 8 14}
{cmd:vgettoken}
{it:result_varname} [{it:rest_varname}] : {it:source_varname}
[{cmd:if} {it:exp}]
[{cmd:in} {it:range}]
{cmd:,}
[{cmdab:p:arse(delimiters)} {cmd:nospace} {cmdab:replaceresu:lt} {cmdab:replaceres:t} {cmdab:nodelim:iters}
{p_end}
{title:Description}
{p}
{cmd:vgettoken} does for variables what {help gettoken} does for macros: it pulls a token from each observation of {it:source_varlist}, and stores the result in {it:result_variable}.
If the optional {it:rest_variable} is specified, the remainder (possibly minus the intervening delimiter) is stored in the {it:rest_variable}.
{p_end}
{title:Options}
{p 0 4}{cmd:parse(delimiters)} gives the list of delimiters which are used to separate tokens.
If omitted, the only delimiter is whitespace (one or more spaces).
There is no need to specify space a delimiter, though explicitly specifying it will not cause problems.
{p_end}
{p 0 4}{cmd:nospace} is used to {bf:prevent} spaces from being used as delimiters.
{p_end}
{p 0 4}{cmd:nodelimiters} is used to {bf:prevent} delimiters from being stored as tokens.
Note that just as with {help gettoken}, spaces are never kept as tokens.
{p_end}
{p 0 4}{cmd:replacereslt} allows the {it:result_variable} to be overwritten.
{p_end}
{p 0 4}{cmd:replacerest} allows the {it:rest_variable} to be overwritten.
{p_end}
{title:Example(s)}
{p 8 12}{inp:. vgettoken foo : bar}{break}
Will take the first word (space delimited!) from each observation in {it:bar} and put it in the corresponding observation of {it:foo}, leaving {it:bar} unchanged.
{p_end}
{p 8 12}{inp:. vgettoken foo rest : bar}{break}
Will take the first word from each observation in {it:bar} and put it in the corresponding observation of {it:foo}, leaving {it:bar} unchanged, and putting the remaining words into {it:rest}.
{p_end}
{p 8 12}{inp:. vgettoken foo bar : bar}{break}
Will take the first word from each observation in {it:bar} and put it in the corresponding observation of {it:foo}, and replace {it:bar} with the remaining words.
{p_end}
{p 8 12}{inp:. vgettoken foo : bar, parse(":") nospace}{break}
Will take everything up to the first colon (:) from each observation in {it:bar} and put it in the corresponding observation of {it:foo}, leaving {it:bar} unchanged.
If the first character of an observation of {it:bar} is itself a colon, the colon will be placed in the corresponding observation of {it:foo}.
{p_end}
{p 8 12}{inp:. vgettoken foo rest : bar, parse(":") nospace}{break}
Will take everything up to the first colon (:) from each observation in {it:bar} and put it in the corresponding observation of {it:foo}, leaving {it:bar} unchanged.
If the first character of an observation of {it:bar} is itself a colon, the colon will be placed in the corresponding observation of {it:foo}.
The observations in {it:rest} will contain everything left over, so concatinating {it:foo} and {it:rest} will reconstruct {it:bar}.
{p_end}
{p 8 12}{inp:. vgettoken foo : bar, parse(":") nospace nodelimiters}{break}
Will take everything up to the first colon (:) from each observation in {it:bar} and put it in the corresponding observation of {it:foo}, leaving {it:bar} unchanged.
If the first character of an observation of {it:bar} is itself a colon, an empty observation will be placed in the corresponding observation of {it:foo}.
{p_end}
{p 8 12}{inp:. vgettoken foo rest : bar, parse(":") nospace nodelimiters}{break}
Will take everything up to the first colon (:) from each observation in {it:bar} and put it in the corresponding observation of {it:foo}, leaving {it:bar} unchanged.
If the first character of an observation of {it:bar} is itself a colon, the corresponding observation of {it:foo} will be empty.
The observations in {it:rest} will contain everything left over, except any leading delimiters (just as would happen if spaces were used as the delimiters).
{p_end}
{p 8 12}{inp:. vgettoken foo : bar, parse(":|!")}{break}
Will take everything up to either the first space, colon (:), vertical bar (|), or exclamation point (!) from each observation in {it:bar} and put it in the corresponding observation of {it:foo}, leaving {it:bar} unchanged.
If the first character of an observation of {it:bar} is itself a delimiter, the delimiter will be placed in the corresponding observation of {it:foo} unless the delimiter is a space (or spaces), in which case the observation in {it:foo} will be empty.
{p_end}
{title:Notes}
{p}
While this could possibly be useful for splitting up variables by hand when working with nasty text files, it will probably be more useful to use {help vtokenize} to split up the {it:source_variable} into all its tokens.
{p_end}
{title:Also see}
{p}
{help gettoken}, {help tokenize}, {help vtokenize}
{p_end}
{title:Author}
Bill Rising
email: {browse "mailto:[email protected]":[email protected]}
web: {browse "http://www.louisville.edu/~wrrisi01":http://www.louisville.edu/~wrrisi01}
snailmail:
Department of Bioinformatics and Biostatistics
University of Louisville
Louisville, KY 40292
{title:Last Updated}: December 9, 2003 @ 22:28:15