Statalist The Stata Listserver


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

RE: st: RE: Behaviour of -tokenize- shouldn't it drop the parsing character?


From   "Scott Merryman" <smerryman@kc.rr.com>
To   <statalist@hsphsun2.harvard.edu>
Subject   RE: st: RE: Behaviour of -tokenize- shouldn't it drop the parsing character?
Date   Wed, 4 Oct 2006 20:56:04 -0500

> -----Original Message-----
> From: owner-statalist@hsphsun2.harvard.edu [mailto:owner-
> statalist@hsphsun2.harvard.edu] On Behalf Of David Elliott
> Sent: Wednesday, October 04, 2006 8:33 PM
> To: statalist@hsphsun2.harvard.edu
> Subject: Re: st: RE: Behaviour of -tokenize- shouldn't it drop the parsing
> character?
> 
> Thank you, Scott - I didn't have access to the paper manual and -help
> tokenize- omitted that little fact.  Your solution would work with my
> first example but for more complex strings like my example: 1 2 3 | 4
> 5 6| 7 8 | 9 where I want the parse to give me the groups separated by
> the "|" as tokens - not the individual items within the groups (that
> comes later).  For now I am going to do the following:
> 
> local test 1 2 3 | 4 5 6| 7 8 | 9
> tokenize `"`test'"' , parse("|")
> local i = 1
> while `"`i'"' != "" {
>     tokenize `"`i'"'
>     local j = 1
>     while `"`j'"' != "" {
>         do something with j
>         local ++j
>         }
>     local ++i
>     macro shift  // this advances over the token and allows i to progress
> 1,2,3
>     }
> 
> 
> I still think tokenize *should* have a noparsechar option that does
> not save the parsing characters (Stata, are you listening?).
>

Another thought:  can this problem be avoided by using an -ifcmd- statement
to ignore the positional macros with "|".  Something like this:

local test 1 2 3 | 4 5 | 6 7 8 | 9
tokenize "`test'", p(|)
while "`1'" != "" {
	if "`1'" != "|" {
		disp "`1'"
		}
macro shift
}

Scott



*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



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