-
Hi Primo,
perfectly valid, but this explicit length check is more safe:
Code:
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:
Code:
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
-
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
Code:
Dim sb As New StringBuilder
sb.Add("Ciao world")
sb.Add("Ciao world")
Dim s As String * sb.Length At sb.DataPtr
PrintL s
-
Hi primo,
I meant that you can do:
Code:
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