M mindful Active Member Licensed User Mar 23, 2017 #1 Which method offers the best performance to join together two strings ? 1. Code: Copy Dim finalString As String = String1 & String2 2. Code: Copy Dim finalString As String = $"${String1}${String2}"$ 3. Code: Copy Dim sb As StringBuilder sb.Initialize sb.Append(String1) sb.Append(String2) Dim finalString As String = sb.ToString I am looking for a method that will be used in general (short, long, very long strings which are made from 2 strings or more) ... for now I am using the 1st and the 2nd but I saw a post (can't find it) that suggested that for long strings composed of many parts (not just two) it is performance wise to use the 3rd method ...
Which method offers the best performance to join together two strings ? 1. Code: Copy Dim finalString As String = String1 & String2 2. Code: Copy Dim finalString As String = $"${String1}${String2}"$ 3. Code: Copy Dim sb As StringBuilder sb.Initialize sb.Append(String1) sb.Append(String2) Dim finalString As String = sb.ToString I am looking for a method that will be used in general (short, long, very long strings which are made from 2 strings or more) ... for now I am using the 1st and the 2nd but I saw a post (can't find it) that suggested that for long strings composed of many parts (not just two) it is performance wise to use the 3rd method ...
EnriqueGonzalez Expert Licensed User Longtime User Mar 23, 2017 #2 Hi! The post you are looking was between erel and ilan and erel demonstrated that stringbuilder is 10 times faster than the other 2 methods. You may not find the post because it was on the chit chat section Upvote 0
Hi! The post you are looking was between erel and ilan and erel demonstrated that stringbuilder is 10 times faster than the other 2 methods. You may not find the post because it was on the chit chat section
Erel B4X founder Staff member Licensed User Longtime User Mar 24, 2017 #3 For a few strings the difference will not matter. If there are many concatenations then you should definitely use StringBuilder. The relevant discussion: https://www.b4x.com/android/forum/threads/get-a-random-string.75903/#post-481749 (StringBuilder is 100 times faster). Upvote 0
For a few strings the difference will not matter. If there are many concatenations then you should definitely use StringBuilder. The relevant discussion: https://www.b4x.com/android/forum/threads/get-a-random-string.75903/#post-481749 (StringBuilder is 100 times faster).