Results 1 to 10 of 13

Thread: StringBuilder for ThinBASIC @ GitHub

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Super Moderator Petr Schreiber's Avatar
    Join Date
    Aug 2005
    Location
    Brno - Czech Republic
    Posts
    7,128
    Rep Power
    732

    StringBuilder for ThinBASIC @ GitHub

    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
    Attached Images Attached Images
    Last edited by Petr Schreiber; 17-12-2016 at 11:59.
    Learn 3D graphics with ThinBASIC, learn TBGL!
    Windows 10 64bit - Intel Core i5-3350P @ 3.1GHz - 16 GB RAM - NVIDIA GeForce GTX 1050 Ti 4GB

Members who have read this thread: 0

There are no members to list at the moment.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •