realblue Member Licensed User Longtime User Sep 7, 2015 #1 Hi everybody, I like to initialize a string with 10 * 8192 spaces. Is there a simple way like in Visual Basic : StrDup(10*8192," ")
Hi everybody, I like to initialize a string with 10 * 8192 spaces. Is there a simple way like in Visual Basic : StrDup(10*8192," ")
eurojam Well-Known Member Licensed User Longtime User Sep 7, 2015 #2 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
not so short, not very elegant, but should work Code: Copy Dim s As String = "" For i = 1 To 81920 s = s & " " Next
realblue Member Licensed User Longtime User Sep 7, 2015 #3 Yes of course but may be there is an efficient way Upvote 0
eurojam Well-Known Member Licensed User Longtime User Sep 7, 2015 #4 use stringfunctions lib: AddSpaces (HowMany As Int) As String Upvote 0
eurojam Well-Known Member Licensed User Longtime User Sep 7, 2015 #5 https://www.b4x.com/android/forum/threads/string-functions.10365/ Upvote 0
realblue Member Licensed User Longtime User Sep 7, 2015 #6 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
Thank you eurojam but I rather use for next since the library will load a lot of code that I don't use.
Erel B4X founder Staff member Licensed User Longtime User Sep 7, 2015 #7 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
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