0

I want to append string in front.

'For example 
Dim value As String = "a"

'I want to append the 'value' string so that it prints the below:
' gfedcba

I found the below thread which tells the solution for my problem:
http://www.daniweb.com/forums/thread139781.html

But I was wondering if there is way to achieve the same result using "&" instead of "+" ?

Thanks.

4
Contributors
3
Replies
5
Views
7 Years
Discussion Span
Last Post by k1robert
0

+ is the string concatenation operator in C#, which is the language of the thread you referred to. & is the concatenation operator for VB. You can certainly use it in your problem.

0

Yes you can and should use an ampersign instead of a plus sign.

With that said though, concatenating strings isn't the most efficient way to program. Although you may only be using one variable, every time you concatenate into that variable it is actually making a new variable in memory.

I wouldnt worry about it with something as small as you mention but something to keep in mind when using a lot of concatenation such as in a loop. It is much more memory efficient and faster to use a sting builder instead.

0
'using the stringbuilder is less expensive 
        'make sure you use Imports System.Text
        Dim value As StringBuilder
        value.Append("a")
        value.Append("b")
        value.Append("c")

        'to use it - this will print abc
        MessageBox.Show(value.ToString())
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.