REM. Routine to emulate the SPLIT function available in some BASICs REM. Written by Richard Russell, 13-Mar-2009 REM. Call as follows: num% = FNsplit(str$, delim$, array$()) REM. Where str$ is the string to be split REM. delim$ is the delimiter at which it should be split REM. array$() is an array to receive the parts REM. The returned value is the number of array elements written DEF FNsplit(A$, d$, a$()) LOCAL C%, I%, Q%, R% REPEAT R% = 0 REPEAT C% = INSTR(A$, d$, R%+1) Q% = INSTR(A$, """", R%+1) IF Q% IF C% > Q% THEN R% = INSTR(A$, """", Q%+1) IF R%=0 ERROR 100, "Mismatched quotes" ENDIF UNTIL (Q% = 0) OR (C% <= Q%) IF C% = 0 THEN C% = LEN(A$)+1 a$(I%) = LEFT$(A$, C%-1) A$ = MID$(A$, C%+LEN(d$)) I% += 1 UNTIL A$="" = I%
|
|