Was working on a .PLS file parser in java and suddenly felt the need to make some DB functions. (Which I'm sure I have already written these before at some point, and so have many others)
dim substrings() as string
set cursor 0,0
print "Test string: 'File5=http://205.188.234.66:8010'"
print
print "Test to see if above string starts with 'file' (ignore case)"
print "result -> ",startsWith("File5=http://205.188.234.66:8010","file",1)
print
print "Substring test (7,27)"
print "result -> ",substring$("File5=http://205.188.234.66:8010",7,27)
print
split("thepuppy kitten has puppyblue eyes.","puppy")
c = array count(substrings())
for i = 0 to c
print substrings(i)
next i
suspend for key
`==========================================
`Checks to see if string "s" starts with
`string "prefix"
`1 to ignore case, 0 for case-sensitive
`==========================================
function startsWith(s as String, prefix as String, ignoreCase as boolean )
if ignoreCase
s = lower$(s)
prefix = lower$(prefix)
endif
pLength = len(prefix)
sLength = len(s)
if pLength > sLength then exitfunction 0
temp as string
temp = left$(s, pLength)
if temp = prefix then exitfunction 1
endfunction 0
`==========================================
`Returns a substring from string "s" between
`beginIndex and endIndex, inclusive
`Character positions range from 1 to len(s)
`==========================================
function substring$(s as String, beginIndex as integer, endIndex as integer)
temp as string
temp = left$(s, endIndex)
temp = right$(temp, len(temp)-(beginIndex-1))
endfunction temp
`==========================================
`Splits a string into tokens or seperate
`"pieces", using the specified delimiter.
`Tokens are stored in a string array which
`size ranges from 0 to array count, inclusive
`==========================================
function split(s as String, delim as string)
dLength = len(delim)
flag = 1
while flag = 1
flag = 0
sLength = len(s)
for i = dLength to sLength
temp$ = substring$(s,(i-dLength)+1,i)
if temp$ = delim
appendElement(left$(s,i-dLength))
s = right$(s,sLength-i)
flag = 1
exit
endif
next i
if flag = 0
appendElement(s)
endif
endwhile
endfunction
`==========================================
`Adds string "s" to the end of the array
`used in the function
`==========================================
function appendElement(s as string)
array insert at bottom substrings()
c = array count(substrings())
substrings(c) = s
endfunction
