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
    6,795
    Blog Entries
    3
    Rep Power
    693
    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 7 64bit - Intel Core 2 Duo T6600 @ 2.2GHz - 4 GB RAM - NVIDIA GeForce G210M 512MB
    Windows 8 64bit - Intel Core i5-3350P @ 3.1GHz - 8 GB RAM - NVIDIA GeForce GT640 3GB

  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
    6,795
    Blog Entries
    3
    Rep Power
    693
    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 7 64bit - Intel Core 2 Duo T6600 @ 2.2GHz - 4 GB RAM - NVIDIA GeForce G210M 512MB
    Windows 8 64bit - Intel Core i5-3350P @ 3.1GHz - 8 GB RAM - NVIDIA GeForce GT640 3GB

Page 2 of 2 FirstFirst 12

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
  •