Search This Blog

Monday, January 14, 2013

Concatenate string VB.NET

VB.NET > String > Concatenate

You can use +, & operators and Concat method.
Concat concatenates one or more instances of String.

The + and & operators are not identical in VB.NET.
  • & is only used for string concatenation
  • + is overloaded to do both string concatenation and arithmetic addition.

Example

1. Using & operator with strings

Dim str1 As String = "Visual "
Dim str2 As String = "Basic"
' Concatenate
Dim str3 = str1 & str2
MessageBox.Show(str3)


 
2. Using & operator with string and number

Dim str1 As String = "Visual Basic "
Dim str2 As Integer = 6

' Concatenate
Dim str3 = str1 & str2
MessageBox.Show(str3)


3. Concat Method

Dim str1 As String = "Visual"
Dim str2 As Integer = 6
' Concatenate
Dim str3 = String.Concat(str1, " ", str2)
MessageBox.Show(str3)