DAY 032: _INSTRREV
#7
Oh, that's what you were shooting for. Okay, maybe you were just over-thinking it?

Code: (Select All)
a$ = "much Steve go or after full Steve then if"
PRINT a$: PRINT

DO
    LOCATE 10, 1: PRINT SPACE$(_WIDTH);
    LOCATE 10, 1: LINE INPUT "Search term: "; b$
    j = instrrev&(seed&, a$, b$)
    PRINT: PRINT "INSTRREV ="; _INSTRREV(seed&, a$, b$), "Function ="; j
    LOCATE 2: PRINT SPACE$(_WIDTH);
    IF j THEN LOCATE 2, j: PRINT "^"
LOOP

FUNCTION instrrev& (seed&, strng$, srch$)
    b$ = SPACE$(LEN(srch$))
    FOR i& = LEN(b$) TO 1 STEP -1
        j& = j& + 1
        MID$(b$, j&, 1) = MID$(srch$, i&, 1)
    NEXT
    j& = 0
    a$ = SPACE$(LEN(strng$))
    FOR i& = LEN(a$) TO 1 STEP -1
        j& = j& + 1
        MID$(a$, j&, 1) = MID$(strng$, i&, 1)
    NEXT
    IF INSTR(seed&, a$, b$) THEN
        instrrev& = LEN(a$) - LEN(b$) - (INSTR(seed&, a$, b$) - 2)
    ELSE
        instrrev& = 0
    END IF
END FUNCTION

I get the two Steve's now. It needs to pick out the second one to be _INSTRREV() compliant. Good thinking!

Pete
Reply


Messages In This Thread
DAY 032: _INSTRREV - by Pete - 12-12-2022, 08:58 PM
RE: DAY 032: _INSTRREV - by vince - 12-12-2022, 09:10 PM
RE: DAY 032: _INSTRREV - by mnrvovrfc - 12-12-2022, 09:10 PM
RE: DAY 032: _INSTRREV - by vince - 12-12-2022, 09:39 PM
RE: DAY 032: _INSTRREV - by Pete - 12-12-2022, 10:20 PM
RE: DAY 032: _INSTRREV - by vince - 12-13-2022, 12:03 AM
RE: DAY 032: _INSTRREV - by Pete - 12-13-2022, 01:35 AM
RE: DAY 032: _INSTRREV - by vince - 12-13-2022, 02:02 AM
RE: DAY 032: _INSTRREV - by SMcNeill - 12-13-2022, 09:34 AM
RE: DAY 032: _INSTRREV - by mnrvovrfc - 12-13-2022, 11:16 AM
RE: DAY 032: _INSTRREV - by SMcNeill - 12-13-2022, 09:43 AM
RE: DAY 032: _INSTRREV - by Pete - 12-13-2022, 02:52 PM



Users browsing this thread: 1 Guest(s)