I write code in Java, PHP, C# and some C on Arduino. I used to write some Basic when I was a kid and I really liked this language.
For my projects I often use string expressions to pass data between web services, microcontrollers and desktop applications and the Split algorithm is something I oftenly use. I got involved with FreeBasic a week ago and I found out that Split command is not onboard so I had to write my own.
Hope you find it useful !
Code: Select all
/'
Split Text Algorithm v2.0 for FreeBasic
Author: Nikos Siatras
https://github.com/nsiatras
'/
' Splits the textToSplit string into multiple Strings, given the delimiter
' that separates them and adds them to the result array
Sub Split(byval stringToSplit as String, delimeter as const String, result() as String)
Dim lengthOfDelimeter as Integer = len(delimeter)
Dim indexOfDelimeter as Integer = Instr(stringToSplit, delimeter)
Dim counter as Integer = 0
while (indexOfDelimeter > 0)
Redim preserve result(counter+1)
result(counter) = mid(stringToSplit, 1, indexOfDelimeter - 1)
stringToSplit = mid(stringToSplit,indexOfDelimeter + lengthOfDelimeter)
indexOfDelimeter = Instr(stringToSplit, delimeter)
counter += 1
wend
result(counter) = stringToSplit
End Sub
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Test Code
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Dim fStringToSplit as String
Dim fSplitParts () as String
fStringToSplit = "Hello,World,!"
Split(fStringToSplit,",",fSplitParts())
for i as Integer =0 to ubound(fSplitParts)
print "Part #" &i & " = " & fSplitParts(i)
next
https://codemammoth.blogspot.com/2022/0 ... basic.html