position of the LAST occurrence of needle in haystack

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

position of the LAST occurrence of needle in haystack

Jignesh Sutar
The string function INDEX finds the position of the *first* occurrence of needle in haystack but is there a function or workaround to find the *last* occurrence? I've searched previous posting and couldn't find anything...
 
I give an example of splitting the directory of a path and file name...
 
data list list / dir(a256).
begin data
"C:\Program Files (x86)\SPSS\Employee data.sav"
end data.
 
string path fName(a256).
*<some commands to do the job>.
 
 
Many thanks
Jignesh
Reply | Threaded
Open this post in threaded view
|

Re: position of the LAST occurrence of needle in haystack

Jon K Peck
Use Char.Rindex (or Rindex in versions prior to 16).

Jon Peck
Senior Software Engineer, IBM
[hidden email]
312-651-3435




From:        J Sutar <[hidden email]>
To:        [hidden email]
Date:        01/11/2011 06:38 AM
Subject:        [SPSSX-L] position of the LAST occurrence of needle in haystack
Sent by:        "SPSSX(r) Discussion" <[hidden email]>




The string function INDEX finds the position of the *first* occurrence of needle in haystack but is there a function or workaround to find the *last* occurrence? I've searched previous posting and couldn't find anything...
 
I give an example of splitting the directory of a path and file name...
 
data list list / dir(a256).
begin data
"C:\Program Files (x86)\SPSS\Employee data.sav"
end data.

 
string path fName(a256).
*<some commands to do the job>.
 
 
Many thanks
Jignesh