> From:  Hari T. K. Varma
> Is there any direct one step method to locate the position of 
> last occurrence of a Sub-string in an existing string.
> For ex:- to locate the last occurrence of "AC" in the string 
> X="AC2BC2CD2AC2AC2BC2SS" for this case the position should be 
> returned 5.
> Your valuable inputs will be appreciated

I can't think of a good easy way.
Suggestions so far involve traversing the string twice, which may be
nasty for really long strings.  
I think the following substring extractions would involve a direct jumps
to those bites being tested, rather than reading forward:

X="AC2BC2CD2AC2AC2BC2SS"
LOOKFOR = "AC"
FOR I = LEN(X) TO 1 STEP -1
UNTIL ( X[ I, LEN( LOOKFOR ) ] = LOOKFOR )
NEXT I
CRT I, X[I, LEN( LOOKFOR )]  ;* I will be 0 if LOOKFOR is not found.
-------
u2-users mailing list
[email protected]
To unsubscribe please visit http://listserver.u2ug.org/

Reply via email to