[futurebasic] INSTRREVERSE

Message: < previous - next > : Reply : Subscribe : Cleanse
Home   : October 2001 : Group Archive : Group : All Groups

From: AlStaff@...
Date: Thu, 25 Oct 2001 19:20:38 EDT
Has anyone contributed a INSTRREVERSE FN yet? It searchs for a string 
starting from the right instead of the left.



/*
INSTRREVERSE by Al Staffieri Jr. - 10/25/2001
This function will search a string starting from the end of the string 
instead of the beginning. 
 - searchForString$ is the string you want to search for.
 - stringToSearch$ is the string being searched.
 - startpos is the starting position for the search. The search is done 
backwards starting from the startpos charcter. Leave it 0 to start at the end.
 - caseFlag is for case sensitive searches. 0 is not case sensitive. any 
other number means the search will be case sensitive.
 - position will be the starting character position where the string was 
found.
*/
LOCAL FN InstrReverse(searchForString$, stringToSearch$, startpos, caseFlag)
 DIM position
 DIM tempstringToSearch$

 IF caseFlag = 0 THEN searchForString$ = UCASE$(searchForString$)
 IF caseFlag = 0 THEN stringToSearch$ = UCASE$(stringToSearch$) 
 IF startpos > LEN(stringToSearch$) THEN startpos = LEN(stringToSearch$)
 IF startpos < 1 THEN startpos = LEN(stringToSearch$)
 position = 0

 DO
tempstringToSearch$ = MID$(stringToSearch$, startpos,LEN(searchForString$))
IF searchForString$ = tempstringToSearch$ THEN position = startpos
IF position = 0 THEN startpos = startpos - 1
IF startpos < 1 THEN position = -1
 UNTIL position <> 0

 IF position < 1 THEN position = 0
END FN = position



WINDOW 1

searchForString$ = "ert"
stringToSearch$ = "Albert Robert Staffieri Jr."

position = FN InstrReverse(searchForString$, stringToSearch$, startpos, 
caseFlag)

PRINT position
LONG IF position = 0
PRINT "STRING NOT FOUND"
XELSE
PRINT mid$(stringToSearch$, position)
END IF

WHILE 1
HANDLEEVENTS
WEND




Al Staffieri Jr.

AlStaff@...
http://members.aol.com/AlStaff/index.html