Rio, Martin
> I would like to specify a command to tell me the position
> in a string of the
> first character that is not a space. Example:
>
> " one" would yield 1
> " two" would yield 2
> " three" would yield 3
> and so on...
>
> Just so you know why in the world I'd want to do this, the
> number of spaces
> determines hierarchy in my dataset. I was thinking of using
> the index
> function, but I'm not sure how to specify 'not a space' for
> the second
> argument.
By my count the "o" in " one" is at position 2,
etc. using the Stata convention which is to start at 1.
It seems however that you may want to start
counting at 0. As the difference is obvious,
I will just look at start 1.
One way to do this to get the number of leading
spaces from
length(string) - length(ltrim(string))
and to add 1.
Alternatively,
index(string, ltrim(string))
is another way to step towards what you
want.
I don't know a way to specify "not a space"
directly.
Nick
[email protected]
*
* 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/