Android Question Initialize a string

realblue

Member
Licensed User
Longtime User
Hi everybody,

I like to initialize a string with 10 * 8192 spaces. Is there a simple way like in Visual Basic : StrDup(10*8192," ")
 
not so short, not very elegant, but should work;)
Code: Copy
  Dim s As String = ""
  For i = 1 To 81920
    s = s & " "
  Next
 
Upvote 0
Thank you eurojam but I rather use for next since the library will load a lot of code that I don't use.
 
Upvote 0
Strings are immutable objects. You shouldn't concatenate 81920 characters one by one. It will be slow.

You should use StringBuilder instead.

Or another option:
Code: Copy
Sub CreateSpace(Length As Int) As String
   Dim b(Length) As Byte
   Dim s As Int = Asc(" ")
   For i = 0 To b.Length - 1
     b(i) = s
   Next
   Return BytesToString(b, 0, b.Length, "ASCII")
End Sub
 
Upvote 0
Back
Top