Page 2 of 2 FirstFirst 12
Results 11 to 13 of 13

Thread: StringBuilder for ThinBASIC @ GitHub

  1. #11
    Super Moderator Petr Schreiber's Avatar
    Join Date
    Aug 2005
    Location
    Brno - Czech Republic
    Posts
    7,155
    Rep Power
    736
    Hi Primo,

    perfectly valid, but this explicit length check is more safe:
    Uses "StringBuilder", "Console"
     
    Dim sb As New StringBuilder
       
    sb.Add("Ciao world")
    sb.Add("Ciao world")
       
    Dim s As String * 4 At sb.DataPtr 
      
    PrintL s
    printl 
     
    Long pointer
    pointer = sb.DataPtr 
    String st 
    long i
    
    
    For i=1 To sb.Length
      st = Peek$(pointer, i)
      PrintL st
    Next
     
    WaitKey
    
    With this in mind, it is natural that you can reach the string inside like:
    Uses "StringBuilder", "Console"
     
    Dim sb As New StringBuilder
       
    sb.Add("Ciao world")
    sb.Add("Ciao world")
       
    Dim s As String * sb.Length At sb.DataPtr 
      
    PrintL s
     
    WaitKey
    

    Petr
    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

  2. #12
    Hi Petr
    you said in the announcement of TB 1.10.1 http://www.thinbasic.com/community/s...ll=1#post93686
    that StringBuilder can be correctly initialized via string
    what does that mean ?
    you already have posted above how to initialize a StringBuilder
    Dim sb As New StringBuilder
    sb.Add("Ciao world")
    sb.Add("Ciao world")
    Dim s As String * sb.Length At sb.DataPtr 
    PrintL s
    

  3. #13
    Super Moderator Petr Schreiber's Avatar
    Join Date
    Aug 2005
    Location
    Brno - Czech Republic
    Posts
    7,155
    Rep Power
    736
    Hi primo,

    I meant that you can do:
    Dim sb As New StringBuilder("Ciao")
    
    It will set initial text plus set internal capacity to double of initial text length (speed optimization for further additions).


    Petr
    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

Page 2 of 2 FirstFirst 12

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
  •