Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
18
Task/Tokenize-a-string/QB64/tokenize-a-string-1.qb64
Normal file
18
Task/Tokenize-a-string/QB64/tokenize-a-string-1.qb64
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
a$ = "Hello,How,Are,You,Today" ' | Initialize original string.
|
||||
FOR na = 1 TO LEN(a$) ' | Start loop to count number of commas.
|
||||
IF MID$(a$, na, 1) = "," THEN nc = nc + 1 ' | For each comma, increment nc.
|
||||
NEXT ' | End of loop.
|
||||
DIM t$(nc) ' | Dim t$ array with total number of commas (nc). Array base is 0.
|
||||
FOR nb = 1 TO LEN(a$) ' | Start loop to find each word.
|
||||
c$ = MID$(a$, nb, 1) ' | Look at each character in the string.
|
||||
IF c$ = "," THEN ' | If the character is a comma, increase the t$ array for the next word.
|
||||
t = t + 1 ' | t = token word count. Starts at 0 because array base is 0.
|
||||
ELSE ' | Or...
|
||||
t$(t) = t$(t) + c$ ' | Add each character to the current token (t$) word.
|
||||
END IF ' | End of decision tree.
|
||||
NEXT ' | End of loop.
|
||||
FOR nd = 0 TO t ' | Start loop to create final desired output.
|
||||
tf$ = tf$ + t$(nd) + "." ' | Add each token word from t$ followed by a period to the final tf$.
|
||||
NEXT ' | End of loop.
|
||||
PRINT LEFT$(tf$, LEN(tf$) - 1) ' | Print all but the last period of tf$.
|
||||
END ' | Program end.
|
||||
28
Task/Tokenize-a-string/QB64/tokenize-a-string-2.qb64
Normal file
28
Task/Tokenize-a-string/QB64/tokenize-a-string-2.qb64
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
a$ = "Hello,How,Are,You,Today" ' | Initialize original string.
|
||||
DIM t$(LEN(a$) / 2) ' | Create an overestimated sized array.
|
||||
FOR nd = 1 TO LEN(a$) ' | Start loop to find each comma.
|
||||
IF MID$(a$, nd, 1) = "," THEN ' | If a comma is found...
|
||||
tc = tc + 1 ' | Increment tc for each found comma.
|
||||
t$(tc) = word$(a$, tc, ",") ' | Assign tc word to t$(tc) array.
|
||||
END IF ' | End decision tree.
|
||||
NEXT ' | End loop.
|
||||
t$(tc + 1) = word$(a$, tc + 1, ",") ' | Assign last word to next array position.
|
||||
ft$ = t$(1) ' | Start final return string ft$ with first array value.
|
||||
FOR ne = 2 TO tc + 1 ' | Start loop to add periods and array values.
|
||||
ft$ = ft$ + "." + t$(ne) ' | Concatenate a period with subsequent array values.
|
||||
NEXT ' | End loop.
|
||||
PRINT ft$ ' | Print final return string ft$.
|
||||
|
||||
FUNCTION word$ (inSTG$, inDEC, inPRM$) ' | word$ function accepts original string, word number, and separator.
|
||||
inSTG$ = inSTG$ + inPRM$ ' | Add a separator to the end of the original string.
|
||||
FOR na = 1 TO LEN(inSTG$) ' | Start loop to count total number of separators.
|
||||
IF MID$(inSTG$, na, 1) = inPRM$ THEN nc = nc + 1 ' | If separator found, increment nc.
|
||||
NEXT ' | End loop.
|
||||
IF inDEC > nc THEN word$ = "": GOTO DONE ' | If requested word number (inDEC) is greater than total words (nc), bail.
|
||||
FOR nd = 1 TO inDEC ' | Start loop to find requested numbered word.
|
||||
last = st ' | Remember the position of the last separator.
|
||||
st = INSTR(last + 1, inSTG$, inPRM$) ' | Find the next separator.
|
||||
NEXT ' | End loop.
|
||||
word$ = MID$(inSTG$, last + 1, st - last - 1) ' | Return requested word.
|
||||
DONE: ' | Label for bail destination of word count error check.
|
||||
END FUNCTION ' | End of function.
|
||||
Loading…
Add table
Add a link
Reference in a new issue