Stata 11 help for tokenize

help tokenize -------------------------------------------------------------------------------

Title

[P] tokenize -- Divide strings into tokens

Syntax

tokenize [[`]"][string]["[']] [, parse("pchars") ]

Description

tokenize divides string into tokens, storing the result in `1', `2', ... (the positional local macros). Tokens are determined based on the parsing characters pchars, which default to a space if not specified.

Option

parse("pchars") specifies the parsing characters. If parse() is not specified, parse(" ") is assumed, and string is split into words.

Remarks

tokenize may be used as an alternative or supplement to the syntax command for parsing command-line arguments. Generally, it is used to further process the local macros created by syntax, as shown below.

program myprog version 11 syntax [varlist] [if] [in] marksample touse

tokenize `varlist' local first `1' macro shift local rest `*' ... end

Examples

. tokenize some words . di "1=|`1'|, 2=|`2'|, 3=|`3'|"

. tokenize "some more words" . di "1=|`1'|, 2=|`2'|, 3=|`3'|, 4=|`4'|"

. tokenize `""Marcello Pagano""Rino Bellocco""' . di "1=|`1'|, 2=|`2'|, 3=|`3'|"

. local str "A strange++string" . tokenize `str' . di "1=|`1'|, 2=|`2'|, 3=|`3'|"

. tokenize `str', parse(" +") . di "1=|`1'|, 2=|`2'|, 3=|`3'|, 4=|`4'|, 5=|`5'|, 6=|`6'|"

. tokenize `str', parse("+") . di "1=|`1'|, 2=|`2'|, 3=|`3'|, 4=|`4'|, 5=|`5'|, 6=|`6'|"

. tokenize . di "1=|`1'|, 2=|`2'|, 3=|`3'|"

Also see

Manual: [P] tokenize

Help: [P] foreach, [P] gettoken, [P] macro, [P] syntax


© Copyright 1996–2009 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index