$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 "MLIB5" '/*------------------------------------------------------------------*/ ' INDEX(NEEDLE,HAYSTACK,START) ' Returns the position of NEELDE within HAYSTACK. If NEEDLE is ' not found or is a null string, 0 is returned. If START = 0 then ' START is set to 1. If START > length of HAYSTACK, 0 is returned. ' Search of HAYSTACK starts at START. ' EXAMPLE: INDEX("day","saturday",1) = 6 ' INDEX("x","abc def ghi",1) = 0 ' INDEX(" ","abc def ghi",1) = 4 ' INDEX(" ","abc def ghi",5) = 8 ' INDEX(" ","abc def ghi",20) = 0 '/*------------------------------------------------------------------*/ FUNCTION INDEX(BYVAL NEEDLE AS STRING, BYVAL HAYSTACK AS STRING, BYVAL S AS INTEGER) PUBLIC AS INTEGER IF S = 0 THEN S = 1 XRET = 0 IF LEN(NEEDLE) > 0 AND LEN(HAYSTACK) > 0 AND S < LEN(HAYSTACK) THEN XRET = INSTR(S,HAYSTACK,NEEDLE) END IF INDEX = XRET END FUNCTION '/*------------------------------------------------------------------*/ ' CLS ' PRINT INDEX("day","saturday",1);" 6 " ' PRINT INDEX("x","abc def ghi",1);" 0 " ' PRINT INDEX(" ","abc def ghi",1);" 4 " ' PRINT INDEX(" ","abc def ghi",5);" 8 " ' INPUT Z