Split1000 (simple string parser)Contributor(s):
@bplus,
@luke,
@SMcNeill Source: qb64.org Forum
URL:
https://www.qb64.org/forum/index.php?topic=1073.0Tags: [string] [parsing]
Description:
This SUB will take a given N delimited string, and delimiter$ and creates an array of N+1 strings using the LBOUND of the given dynamic array to load.Source Code:
_TITLE "Split demo 2" ' started by B+ on 08-27-2019 to compare to Item$ demo 'new data setup structure to streamline code in setup
'globals seen inside SUBs and FUNCTIONs because SHARED
'VVVV REDIM means dynamic arrays, so can change in setup
'locals just seen in following main code section
setup
PRINT SPACE$(15);
"String Item:"; j;
LIST$
(j
) 'j-1 counts off the items after the first
SUB setup
'3rd method of data structure, this is meant to be edited over and over as add to a refine words and substitutes topIndex = 5 ' <<< make modifications to d() and then update this number, that's it!
d(1) = "Months,January,February,March,April,May,June,July,August,September,October,November,December"
d(2) = "Days,Monday,Tuesday,Wednesday,Thursday,Friday,Saturday,Sunday"
d(3) = "Holidays,NewYears Day,MLK Day,Valentine's Day,Easter,Mother's Day,Memorial Day,Father's Day,Independence Day,Bplus Day,Labor Day,Halloween,Thanksgiving,Christmas"
d(4) = "Test no further words/phrases in this line. (And the next test will do an empty string.)"
d(5) = ""
'This SUB will take a given N delimited string, and delimiter$ and creates an array of N+1 strings using the LBOUND of the given dynamic array to load.
'notes: the loadMeArray() needs to be dynamic string array and will not change the LBOUND of the array it is given.
curpos
= 1: arrpos
= LBOUND(loadMeArray
): LD
= LEN(delim
) dpos
= INSTR(curpos
, SplitMeString
, delim
) loadMeArray
(arrpos
) = MID$(SplitMeString
, curpos
, dpos
- curpos
) arrpos = arrpos + 1
curpos = dpos + LD
dpos
= INSTR(curpos
, SplitMeString
, delim
) loadMeArray
(arrpos
) = MID$(SplitMeString
, curpos
)
Bplus Edit: bplus version was collaboration of
@bplus,
@luke,
@SMcNeill URL where the original discussion was started by Luke contains his complementary Join function. The above is bplus version with a couple of revisions tweaked into it since first posting.