To join two strings together in Visual Basic, you use the & operator. For example,
sString = "hello " & sName
Combines the text "hello " and the value of sName, and saves it in the sString variable. An operator that is notably missing in VB 6 an earlier is a way to append a string to another. In VB 6 or earlier, you have to do
sString = sString & " goodbye!"
Which adds " goodbye" to the end of sString. However, this can be extremely inefficient when performing the operation multiple times, or on large strings. (For performance comparisons with a C++ equivilant, take a look here). Fortunately, with VB.NET, the language has been brought into line with most others, and you can now do
sString .= " goodbye!"
instead.
Comments