$CPU 8086 ' make compatible with XT systems $LIB ALL OFF ' turn off all PowerBASIC libraries $ERROR ALL OFF ' turn off all PowerBASIC error checking $OPTIMIZE SIZE ' optimize for smaller code $COMPILE UNIT ' compile to a UNIT (.PBU) '$COMPILE EXE ' compile to a UNIT (.PBU) DEFINT A-Z ' Required for all numeric functions, forces PB to not ' include floating point in UNIT (makes it smaller) '/*------------------------------------------------------------------*/ $CODE SEG "MLIB1" '/*-------------------------------------------------------------------*/ FUNCTION LASTPOS(BYVAL NEEDLE AS STRING, BYVAL HAYSTACK AS STRING, BYVAL START AS INTEGER) PUBLIC AS INTEGER LNEEDLE = LEN(NEEDLE) LHAYSTACK = LEN(HAYSTACK) IF LNEEDLE = 0 OR LHAYSTACK = 0 THEN FUNCTION = 0 GOTO EXITFUNCTION END IF IF START = 0 THEN START = LHAYSTACK S = LHAYSTACK - LNEEDLE + 1 ELSE S = START END IF DO XRET = 0 XT$ = MID$(HAYSTACK,S,LNEEDLE) IF XT$ = NEEDLE THEN XRET = S S = S - 1 LOOP UNTIL XRET <> 0 OR S = 0 FUNCTION = XRET EXITFUNCTION: END FUNCTION '/*-------------------------------------------------------------------*/ ' CLS ' PRINT LASTPOS(" ","abc def ghi",0);" 8 " ' PRINT LASTPOS(" ","abcdefghi",0);" 0 " ' PRINT LASTPOS(" ","abc def ghi",7);" 4 " ' PRINT LASTPOS("lt","deltaepsilon",0);" 3 " ' PRINT LASTPOS("\","C:\TESTING\TEST\",0)" 16 " ' INPUT Z