_TITLE "Item$ Demo" ' B+ start 2019-08-27
'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
FOR i
= 1 TO topIndex
'all the keywords are first Item$ of d() data array keyword$
= Item$
(d
(i
), 1, ","):
PRINT i;
" "; keyword$
j = 2
WHILE Item$
(d
(i
), j
, ",") <> "" 'all words > 1 are sub or subst items of keyword PRINT SPACE$(5); j
- 1; Item$
(d
(i
), j
, ",") 'j-1 counts off the sub item j = j + 1
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 = 6 ' <<< 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) = "Leap Years,2000,2004,2008,2012,2016,2020,2024,2028,2032,2036,2040,...,2096,2104,..."
d(5) = "Test no further words/phrases in this line. (And the next test will do an empty string.)"
d(6) = ""
'Description: Use Item$() Function to treat strings like arrays without having to use an array structure.
' This function does not throw a fit if you ask for an item number (index) it does not have, it just returns an empty string.
' In QB64, Functions can't return arrays through the function name, but they can return strings that the Item$() function can
' translate like an an array index. nItem numbers are the same as Counting numbers positive integers starting at 1.
' eg Item7$ = Item$(CommaDelimitedString$, 7, ",") 'get 7th Item in string
lastd
= 1: d
= INSTR(lastd
, s$
, delimiter$
) c = c + 1
lastd
= d
+ 1: d
= INSTR(lastd
, s$
, delimiter$
) c = c + 1