; $Id: rstrpos.pro,v 1.1 1993/04/02 19:43:31 idl Exp $ FUNCTION RSTRPOS, Expr, SubStr, Pos ;+ ;NAME: ; RSTRPOS ; ;PURPOSE: ; Finds the last occurrence of a substring within an object string. ; If SubStr is in Expr then RSTRPOS returns the character position ; of the match, otherwise it returns -1 ; ;CATEGORY: ; String manipulation. ; ;CALLING SEQUENCE: ; Result = RSTRPOS(Expression, Search String [, Pos]) ; ;INPUTS: ; Expr - The string in which to search for the substring. ; ; SubStr - The substring to be searchs for with Expr. ; ;OPTIONAL INPUT PARAMETERS: ; Pos - The character position before which the search is bugun. ; If Pos is omitted, the search begins at the last character ; in the string. ; ;OUTPUTS: ; Returns the position the substring was found or -1 if the ; substring is not within expr. ; ;SIDE EFFECTS: ; Unlike STRPOS, Expr and SubStr must be strings. ; ;MODIFICATION HISTORY: ; JWG, January, 1993 ;- Len = STRLEN(Expr) IF N_ELEMENTS(Pos) EQ 0 THEN Start=0 ELSE Start = Len - Pos ; Reverse the string RString = REVERSE(BYTE(Expr)) ; Reverse the substring RSubStr = REVERSE(BYTE(SubStr)) SubPos = STRPOS(STRING(RString),STRING(RSubStr),Start) IF SubPos NE -1 THEN SubPos = Len - SubPos - STRLEN(SubStr) RETURN, SubPos END