Visual Basic String Join Method

In visual basic, the string Join method is useful to concatenate all the elements of string array using the specified separator between each element.

 

Following is the pictorial representation of joining two string elements in an array with the specified separator using the Join() method in a visual basic programming language.

 

Visual Basic String Join() Method Representation Diagram

 

If you observe the above diagram, we are concatenating two array elements ”Suresh” and “Dasari” by using Join method with defined separator “, ” and the Join method has returned the string like “Suresh, Dasari”.

Visual Basic String Join Method Syntax

Following is the syntax of defining a Join method to append or concatenate string array elements using a specified separator in a visual basic programming language.

 

Public Shared Function Join(ByVal separator As String, ByVal ParamArray values As String()) As String

Public Shared Function Join(ByVal separator As String, ByVal ParamArray values As Object()) As String

Public Shared Function Join(ByVal separator As String, ByVal values As IEnumerable(Of String)) As String

If you observe the above syntaxes, the Join method will append or concatenate all the items of array or list using the specified separator between each element.

Visual Basic String Join Method Example

Following is the example of using Join() method to append or concatenate all the string array elements using a specified separator in a visual basic programming language.

 

Module Module1

    Sub Main()

        Dim sArr As String() = {"Welcome", "to", "Tutlane"}

        Console.WriteLine("Join with Hypen: {0}", String.Join("-", sArr))

        Dim sArr1 As String() = {"Suresh", "Rohini", "Trishika"}

        Console.WriteLine("Join with Comma: {0}", String.Join(", ", sArr1))

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

        Console.ReadLine()

    End Sub

End Module

If you observe the above example, we used a string Join() method to append or concatenate all the elements of string array using a specified separator.

 

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

 

Visual Basic (VB) String Join() Method Example Result

 

This is how we can use the string Join() method to append or concatenate all string array elements using a specified separator in a visual basic programming language.