Windows apps
Collapse the table of content
Expand the table of content
Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

String.Join Method (String, String())

 
System_CAPS_noteNote

The .NET API Reference documentation has a new home. Visit the .NET API Browser on docs.microsoft.com to see the new experience.

Concatenates all the elements of a string array, using the specified separator between each element.

Namespace:   System
Assembly:  mscorlib (in mscorlib.dll)

Public Shared Function Join (
	separator As String,
	ParamArray value As String()
) As String

Parameters

separator
Type: System.String

The string to use as a separator. separator is included in the returned string only if value has more than one element.

value
Type: System.String()

An array that contains the elements to concatenate.

Return Value

Type: System.String

A string that consists of the elements in value delimited by the separator string. If value is an empty array, the method returns String.Empty.

Exception Condition
ArgumentNullException

value is null.

For example, if separator is ", " and the elements of value are "apple", "orange", "grape", and "pear", Join(separator, value) returns "apple, orange, grape, pear".

If separator is null, an empty string (String.Empty) is used instead. If any element in value is null, an empty string is used instead.

The following example demonstrates the Join method.

Imports System

Public Class JoinTest

    Public Shared Sub Main()

        Console.WriteLine(MakeLine(0, 5, ", "))
        Console.WriteLine(MakeLine(1, 6, "  "))
        Console.WriteLine(MakeLine(9, 9, ": "))
        Console.WriteLine(MakeLine(4, 7, "< "))
    End Sub 'Main


    Private Shared Function MakeLine(initVal As Integer, multVal As Integer, sep As String) As String
        Dim sArr(10) As String
        Dim i As Integer


        For i = initVal To (initVal + 10) - 1
            sArr((i - initVal)) = [String].Format("{0,-3}", i * multVal)

        Next i
        Return [String].Join(sep, sArr)
    End Function 'MakeLine
End Class 'JoinTest
' The example displays the following output:
'       0  , 5  , 10 , 15 , 20 , 25 , 30 , 35 , 40 , 45
'       6    12   18   24   30   36   42   48   54   60
'       81 : 90 : 99 : 108: 117: 126: 135: 144: 153: 162
'       28 < 35 < 42 < 49 < 56 < 63 < 70 < 77 < 84 < 91

Universal Windows Platform
Available since 8
.NET Framework
Available since 1.1
Portable Class Library
Supported in: portable .NET platforms
Silverlight
Available since 2.0
Windows Phone Silverlight
Available since 7.0
Windows Phone
Available since 8.1
Return to top
Show:
© 2017 Microsoft