I knew this would come in handy one day... look at the "split" function. There's a buggier version of it at the code post. I dont remember if i ever finished it, I think I kept running out of stack space on some of the more recursive functions. *shrug* whatever. I'm pretty sure 'split' works fine. Just say
and it puts all the parts into array(). you can then use val or whatever qb's function is.
Oh, i'm just so happy I havent wasted my time with this. I think I'll recreate those perl array functions too, I'm so happy....
...
naaaah.
Code:
DEFINT A-Z
'$DYNAMIC
REM $STATIC
FUNCTION between$ (text$, tag1$, tag2$, start)
s = INSTR(start, text$, tag1$) + LEN(tag1$)
e = INSTR(s, text$, tag2$)
IF s = 0 OR e = 0 OR s > e THEN between$ = "" ELSE between$ = MID$(text$, s, e - s)
END FUNCTION
FUNCTION join$ (array() AS STRING, inter$)
joined$ = array(LBOUND(array))
FOR x = LBOUND(array) + 1 TO UBOUND(array)
joined$ = joined$ + inter$ + array(x)
NEXT x
join$ = joined$
END FUNCTION
FUNCTION replace$ (text$, replacee$, replacement$)
newtext$ = text$: x = 1
DO
x = INSTR(x, newtext$, replacee$)
IF x <> 0 THEN
newtext$ = splice$(newtext$, x, x + LEN(replacee$), replacement$)
x = x + LEN(replacement$) + 1
END IF
LOOP UNTIL x = 0
replace$ = newtext$
END FUNCTION
FUNCTION replacebetween$ (text$, replacement$, tag1$, tag2$, start)
newtext$ = text$
s = 1: e = 1
DO UNTIL s = 0 OR e = 0 OR s > e
s = INSTR(start, newtext$, tag1$)
e = INSTR(s + LEN(tag1$), newtext$, tag2$)
IF s <> 0 THEN inbetween$ = MID$(newtext$, s, LEN(newtext$) - e) ELSE EXIT DO
temptext$ = replacement$
x = 1
DO
x = INSTR(x, temptext$, "\x")
IF x <> 0 THEN
temptext$ = splice$(temptext$, x, x + 2, inbetween$)
x = x + LEN(inbetween$) + 1
END IF
LOOP UNTIL x = 0
newtext$ = splice$(newtext$, s, e + LEN(tag2$), temptext$)
start = s + 1
LOOP
replacebetween$ = newtext$
END FUNCTION
FUNCTION splice$ (text$, startchar, endchar, text2$)
IF startchar > 0 THEN newtext$ = newtext$ + LEFT$(text$, startchar - 1)
newtext$ = newtext$ + text2$
IF endchar <= LEN(text$) THEN newtext$ = newtext$ + RIGHT$(text$, LEN(text$) - endchar + 1)
splice$ = newtext$
END FUNCTION
SUB split (text$, splitter$, array() AS STRING)
REDIM splist(0 TO LEN(text$)) AS INTEGER
b = 0
n = 0
DO
b = INSTR(b + 1, text$, splitter$)
IF b <> 0 THEN
splist(n) = b
n = n + 1
END IF
LOOP UNTIL b = 0
max = n
REDIM array(max)
splitlen = LEN(splitter$)
n = 0
FOR x = 1 TO LEN(text$)
IF x = splist(n) THEN
n = n + 1
x = x + splitlen
END IF
matchtest = 0
FOR y = 0 TO max
IF x = splist(y) THEN matchtest = 1
NEXT
IF matchtest = 0 THEN array(n) = array(n) + MID$(text$, x, 1)
NEXT x
END SUB