I think I have a String Functions System worked out, nothing particularly clever but now clear sight of getting SB1 code off the rack and ready for test driving. First test demo of some basically needed String Functions:
' Test ag First String Functions.txt b+ 2021-02-23& 24 reworked $ functionName arg1, arg2,...
. Ways to assign a var
. var = numeric expression (this is for a variable expected to be a number)
. var ""literal (starts immediately after 2nd ") probably fastest and cleanest, remember no space!
.
. Introducing: First String Functions Case Insensitive !!! put all literals right next to comma !!!
. HEAD Syntax: var $ Head source$, endCharPos# > var = mid$(source, 1, endCharPos)
. TAIL Syntax: var $ Tail source$, headEndPos# > var = mid$(source$, headEndPos + 1)
. MID1 Syntax: var $ Mid1 source$, charPos# > var = mid$(source$, charPos#, 1)
. MID$ Syntax: var $ Mid$ source$, startPos#, nChars# > var = Mid$(source$, startPos#, nChars#)
. INSTR2 Syntax: var $ Instr2 source$,literalMatch > var = TS$(Instr(source$, find$)
. INSTR3 Syntax: var $ Instr3 start#, source$,literalMatch > var = TS$(Instr(start#,source$, match$))
. LEN Syntax: var $ Len source$ > var = TS$(Len(source$))
. SPC Syntax: var $ Spc amountOfSpaces# > var = SPC(amountOfSpaces)
. & Syntax: var $ & a1,a2,a3,... > var = a1 + a2 + a3 + ...
hw ""Hello World!
char_H ""H
char_W ""W
. Did it take? show how hw was set in code:
' dot in next line should prevent activating "", it does.
. hw ""Hello World!
' test the "" method of variable assignment
. And hw has the value: ;hw;/ and char_H: ;char_H;/ and char_W: ;char_W
hwLen $ len hw
. And hw has the len of: ;hwLen
.
. Here we try String Functions involving MID$: Head, Tail, Mid$, Mid1
hello $ Head hw, 6
world $ Tail hw, 6
low $ Mid$ hw, 4, 4
first $ mid1 hw,1
' actually if the literal is numeric and positive you can have a space after comma.
seventh $ mid1 hw, 7
. / Head 6 chars = *; hello ;*
. / Tail from 6 + 1 = *; world ;*
. / Mid$ from 4, 4 chars = *; low ;*
. / What's at the first (first $ mid1 hw,1)and seventh positions? answer: ;first;/ and ;seventh
.
find_lh $ instr2 hw,h
find_UH $ instr2 hw, char_H
find_W $ instr2 hw, char_W
. / Instr2 has 2 arguments: Search string and the item to match.
. / Instr3 has 3 arguments: startPlaceOfSearch, the StringToSearch, theItemToFind.
. Instr2 Tests:
. Any h's in ;hw;? Answer: ;find_lh
. Any H's in ;hw;? Answer: ;find_UH
. Any W's in ;hw;? Answer: ;find_W
. The original variable hw was derived from 1st letters at (find H) ;find_uH; and at (find W);find_W;.
. / What the L? find all the places it's located, using Instr2, Instr3
. Instr3 Test:
place $ Instr2 hw,l
[
If place
+= cnt;1
. #;cnt; l resides at ;place;# in ;hw;.
+= place;1
place $ Instr3 place, hw,l
El
. / That's all the L, we found.
Exit
Fi
]
. / Testing $ spc n for spaces and $ & arg1,arg2,arg3... concatenate with &
[
+= n;1
space $ spc n
bind $ & hw, space
; bind
chars = chars + hwLen + n
Jmp chars + hwlen + n + 1 > 128
]
.
. Goodnight!
zzz
My strategy is getting strings with all kinds of troublesome potential parsing characters on the loose, contained as values under variable names ASAP! Then! we can use normal parsing characters eg, spaces and commas, even ()'s (but not yet, that's for SB2 with a super evaluator).
PS There was an error in the code output seen in screen shot that I fixed in code. Today's quiz, can you find it?