| Date: | Tue, 12 Jul 2005 22:01:59 -0400 |
| Reply-To: | Richard Ristow <wrristow@mindspring.com> |
| Sender: | "SPSSX(r) Discussion" <SPSSX-L@LISTSERV.UGA.EDU> |
| From: | Richard Ristow <wrristow@mindspring.com> |
| Subject: | Re: String questions |
|
| In-Reply-To: | <5CFEFDB5226CB54CBB4328B9563A12EE023717C4@hqemail2.spss.com > |
| Content-Type: | text/plain; charset="us-ascii"; format=flowed |
|---|
At 08:20 AM 7/12/2005, Peck, Jon wrote:
>The compute below produces the location of the first digit, returning
>0 is there is none. Note that the third argument of index, 1 in this
>case, causes the search string to be considered as n strings of length
>1 rather than looking for the pattern 0123456789.
>
>compute DigitLoc = index('0123456789', name, 1).
Thank you for reminding us! This is really what the third argument of
INDEX is for. (Now, if a *negative* third argument meant "search for
the first character NOT on the list", we'd really have something.)
But, should it be
compute DigitLoc = index(name, '0123456789', 1).
or am I getting confused from the sun? Syntax manual:
INDEX(a1, a2, a3) Return a number that indicates the position of the
first occurrence of a2 in a1. a1 is the string that is searched. a2 is
the string variable or string that is used in the search. If a3 is not
specified, all of a2 is used. For example, INDEX(ALPHA8,'**X*') returns
2 for a case with value X**X**X* for variable ALPHA8. The optional a3
is the number of characters used to divide a2 into separate strings.
Each substring is used for searching and the function returns the first
occurrence of any of the substrings. With the same value X**X**X* for
ALPHA8, both INDEX(ALPHA8, '**X*', 2) and INDEX(ALPHA8, '**X*', 1)
return 1. a3 must be a positive integer and must divide evenly into the
length of a2. The target variable must be numeric. If a2 is not found
within a1, the value 0 is returned.
|