Concatenation Operators in VB.NET

How to join or concatenate strings in VB.Net?

Explanation

Concatenation Operators in VB.NET

Concatenation Operators in VB.NET are used to join or concatenate two strings. The + and & are the basic concatenation operators.
Both these operands can be used to concatenate strings, but the + operator is preferred while concatenating numbers.

Following table lists the Concatenation Operators used in Visual Basic.
Operator Description
+ Exponentiation Operator
& Multiplication Operator
Example:
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles Button1.Click
Dim a As String
Dim b As String
Dim c As String
a = TextBox1.Text
b = TextBox2.Text
c = a + b
MsgBox("String Concatenated using + is::>" & c)
End Sub
Private Sub Button2_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles Button2.Click
Dim x As String
Dim y As String
Dim z As String
x = TextBox1.Text
y = TextBox2.Text
z = x & y
MsgBox("String Concatenated using + is::>" & z)
End Sub
End Class
Description:

In the above example, TextBox1 and TextBox2 are used to get input strings. Using the click event of Button1 and Button2 the strings are concatenated using both plus and ampersand concatenation operators.

Visual Basic Tutorial


Ask Questions

Ask Question