Visual Basic String Concat Method

In visual basic, string Concat method is useful to concatenate or append one string to the end of another string and return a new string.

 

Following is the pictorial representation of appending two strings using the Concat() method in a visual basic programming language.

 

C# String Concat Method Representation Diagram

 

If you observe the above diagram, we are concatenating two strings ”Suresh” and “Dasari” by using the Concat method and return a new string like “SureshDasari”.

Visual Basic String Concat Method Syntax

Following is the syntax of defining a Concat method to append one or more strings in a visual basic programming language.

 

Public Function Concat(ByVal string1 As String, ByVal string2 As String) As String

If you observe the above syntax, the Concat method will append multiple strings and return it as a new string.

Visual Basic String Concat Method Example

Following is the example of using the Concat() method to append or concatenate one or more strings and return it as a new string in a visual basic programming language.

 

Module Module1

    Sub Main()

        Dim msg1 As String = "Welcome to"

        Dim msg2 As String = " " & "tutlane"

        Console.WriteLine("Message: {0}", String.Concat(msg1, msg2))

        Dim name1 As String = "Suresh"

        Dim name2 As String = ", " & "Rohini"

        Dim name3 As String = ", " & "Trishika"

        Console.WriteLine("Users: {0}", String.Concat(String.Concat(name1, name2), name3))

        Console.WriteLine("Press Enter Key to Exit..")

        Console.ReadLine()

    End Sub

End Module

If you observe the above example, we used a Concat() method to append multiple strings and returning it as a new string.

 

When we execute the above visual basic program, we will get the result as shown below.

 

Visual Basic Concat Method Example Result

 

This is how we can use Concat() method to append or concatenate one or more strings into one string in a visual basic programming language.