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.

Recommended Answers

All 3 Replies

+ 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.

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.

'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())
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.