$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) '/*------------------------------------------------------------------*/ DECLARE FUNCTION WORDS(BYVAL X AS STRING) AS INTEGER DECLARE FUNCTION WORDINDEX(BYVAL X AS STRING, BYVAL NBR AS INTEGER) AS INTEGER '/*------------------------------------------------------------------*/ $CODE SEG "MLIB1" '/*------------------------------------------------------------------*/ ' DELWORD(STRING,N,LENGTH) ' Delete word. ' Deletes the sub-string of STRING that starts at the Nth word ' and is of length LENGTH blank(space)-delimited words. If ' LENGTH = 0 then LENGTH is set to number of words in STRING. ' If N is greater than the number of words in STRING, then the ' string is returned unchanged. The string deleted includes any ' blanks following the final word involved, but none of the ' blanks preceding the first word involved. ' EXAMPLE: DELWORD("Now is the time",2,2) = 'Now time' ' DELWORD("Now is the time",3,0) = 'Now is ' ' DELWORD("Now time",5,0); = 'Now time' '/*------------------------------------------------------------------*/ FUNCTION DELWORD(BYVAL X AS STRING, BYVAL N AS INTEGER, BYVAL L AS INTEGER) PUBLIC AS STRING XRET$ = "" NWRDS = WORDS(X) IF N > NWRDS THEN XRET$ = X IF L > NWRDS THEN L = NWRDS IF L = 0 THEN L = NWRDS IF N > 0 AND N < (NWRDS + 1) THEN '/* --- Get Left String ---*/ IF N > 1 THEN SP = WORDINDEX(X,N) ELSE SP = 1 TL$ = "" IF SP > 1 THEN TL$ = LEFT$(X,SP-1) '/* --- Get Right String ---*/ TR$ = "" IF L = NWRDS THEN TR$ = "" IF L < NWRDS THEN LW = N+L SP = WORDINDEX(X,LW) TR$ = MID$(X,SP) END IF XRET$ = TL$ + TR$ END IF FUNCTION = XRET$ END FUNCTION '/*------------------------------------------------------------------*/