Hi all,
I am sure you are all familiar with the concept of StringBuilder - it is little helper which performs efficient string concatenations and often much more. I started working on such a component for ThinBASIC - the language has incredibly epic string handling, but didn't have any stringbuilder... till now!
The usage
... is very simple. You instantiate object, and then use its methods:
Uses "StringBuilder", "Console"
Function TBMain()
Dim stringBuffer As String
Dim sb As StringBuilder
sb = New StringBuilder()
Long i
Dim stopWatch As cTimer
stopWatch = New cTimer()
Print "Appending to classic string: "
stopWatch.Start
For i = 1 To 20000
stringBuffer += "Appending is fine!"
Next
stopWatch.Stop
PrintL stopWatch.ElapsedToString(%CTIMER_MILLISECONDS, "0") + " ms (Total " + Len(stringBuffer) + " characters)"
Print "Appending to string builder: "
stopWatch.Start
For i = 1 To 20000
sb.Add("Appending is fine!")
Next
stopWatch.Stop
PrintL stopWatch.ElapsedToString(%CTIMER_MILLISECONDS, "0") + " ms (Total " + Len(sb.ToString()) + " characters)"
PrintL
PrintL "Press any key to quit..."
WaitKey
End Function
What is it good for?
It is great for efficient string appending. Do you see the code above? Check the speed on your PC or see the screenshot...
The source code
I decided to make the code public, to make possible for others to commit their enhancements. Get the source @GitHub:
https://github.com/petrSchreiber/thi..._StringBuilder
The binaries
Please note StringBuilder is official part of thinBasic since 1.9.16.17! Yay!
You can still grab the latest release from GitHub as well.
Documentation
The documentation is provided at Wiki associated with the repository, please check here:
https://github.com/petrSchreiber/thi...ngBuilder/wiki
Petr
Bookmarks