function upto$(sourceString$, search$)
i = instr(sourceString$, search$)
if i then upto$=left$(sourceString$,i-1) else upto$=sourceString$
end function
function after$(sourceString$, search$)
i = instr(sourceString$, search$)
if i then after$ = mid$(sourceString$,i+len(search$))
end function
function afterlast$(sourceString$, search$)
do : i = j
j = instr(sourceString$, search$, j+1)
loop until j = 0
if i then afterlast$ = mid$(sourceString$,i+len(search$))
end function
function endswith(sourceString$, search$)
endswith = right$(sourceString$,len(search$)) = search$
end function
function remchar$(sourceString$, removeThese$)
remchar$ = sourceString$
for i = 1 to len(removeThese$)
do
j = instr(remchar$, mid$(removeThese$,i,1))
if j then remchar$ = left$(remchar$,j-1);mid$(remchar$,j+1)
loop until j = 0
next
end function
I'm mystified that Carl thinks the new string manipulation functions are worthwhile, when they can be trivially implemented as user-defined functions. I would far rather he had spent the time fixing bugs and/or adding features that genuinely extend the capabilities of LB (LBB should have given him some ideas!).
Anyway, here are replacements which should work in LB 4.04 and LBB:
Code:function upto$(sourceString$, search$)
i = instr(sourceString$, search$)
if i then upto$=left$(sourceString$,i-1) else upto$=sourceString$
end function
function after$(sourceString$, search$)
i = instr(sourceString$, search$)
if i then after$ = mid$(sourceString$,i+len(search$))
end function
function afterlast$(sourceString$, search$)
do : i = j
j = instr(sourceString$, search$, j+1)
loop until j = 0
if i then afterlast$ = mid$(sourceString$,i+len(search$))
end function
function endswith(sourceString$, search$)
endswith = right$(sourceString$,len(search$)) = search$
end function
function remchar$(sourceString$, removeThese$)
remchar$ = sourceString$
for i = 1 to len(removeThese$)
do
j = instr(remchar$, mid$(removeThese$,i,1))
if j then remchar$ = left$(remchar$,j-1);mid$(remchar$,j+1)
loop until j = 0
next
end function Richard. |
|
FUNCTION replstr$(s$, search$, replace$)
DO
i = INSTR(s$, search$, i)
IF i THEN
s$ = LEFT$(s$, i - 1); replace$; MID$(s$, i + LEN(search$))
i = i + LEN(replace$)
END IF
LOOP UNTIL i = 0
replstr$ = s$
END FUNCTION