Skip to main content
.NET Framework Class Library
StringJoin Method (String, String)

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

Namespace:   System
Assembly:  mscorlib (in mscorlib.dll)
Syntax
Public Shared Function Join ( _
	separator As [%$TOPIC/57a79xd0_en-us_VS_110_1_0_0_0_0%], _
	ParamArray value As [%$TOPIC/57a79xd0_en-us_VS_110_1_0_0_0_1%]() _
) As [%$TOPIC/57a79xd0_en-us_VS_110_1_0_0_0_2%]
public static [%$TOPIC/57a79xd0_en-us_VS_110_1_0_1_0_0%] Join(
	[%$TOPIC/57a79xd0_en-us_VS_110_1_0_1_0_1%] separator,
	params [%$TOPIC/57a79xd0_en-us_VS_110_1_0_1_0_2%][] value
)
public:
static [%$TOPIC/57a79xd0_en-us_VS_110_1_0_2_0_0%]^ Join(
	[%$TOPIC/57a79xd0_en-us_VS_110_1_0_2_0_1%]^ separator, 
	... array<[%$TOPIC/57a79xd0_en-us_VS_110_1_0_2_0_2%]^>^ value
)
static member Join : 
        separator:[%$TOPIC/57a79xd0_en-us_VS_110_1_0_3_0_0%] * 
        value:[%$TOPIC/57a79xd0_en-us_VS_110_1_0_3_0_1%][] -> [%$TOPIC/57a79xd0_en-us_VS_110_1_0_3_0_2%]
public static function Join(
	separator : [%$TOPIC/57a79xd0_en-us_VS_110_1_0_4_0_0%], 
	... value : [%$TOPIC/57a79xd0_en-us_VS_110_1_0_4_0_1%][]
) : [%$TOPIC/57a79xd0_en-us_VS_110_1_0_4_0_2%]

Parameters

separator
Type: SystemString

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

value
Type: SystemString

An array that contains the elements to concatenate.

Return Value

Type: SystemString
A string that consists of the elements in value delimited by the separator string. If value is an empty array, the method returns StringEmpty.
Exceptions
ExceptionCondition
ArgumentNullException

value is .

Remarks

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 , an empty string ( StringEmpty) is used instead. If any element in value is , an empty string is used instead.

Examples

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
using System;

public class JoinTest {
    public static void Main() {

        Console.WriteLine(MakeLine(0, 5, ", "));
        Console.WriteLine(MakeLine(1, 6, "  "));
        Console.WriteLine(MakeLine(9, 9, ": "));
        Console.WriteLine(MakeLine(4, 7, "< "));
    }

    private static string MakeLine(int initVal, int multVal, string sep) {

        string [] sArr = new string [10];

        for (int i = initVal; i < initVal + 10; i++)
            sArr[i - initVal] = String.Format("{0,-3}", i * multVal);

        return String.Join(sep, sArr);
    }
}
// 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  
using namespace System;
String^ MakeLine( int initVal, int multVal, String^ sep )
{
   array<String^>^sArr = gcnew array<String^>(10);
   for ( int i = initVal; i < initVal + 10; i++ )
      sArr[ i - initVal ] = String::Format( "{0, -3}", i * multVal );
   return String::Join( sep, sArr );
}

int main()
{
   Console::WriteLine( MakeLine( 0, 5, ", " ) );
   Console::WriteLine( MakeLine( 1, 6, "  " ) );
   Console::WriteLine( MakeLine( 9, 9, ": " ) );
   Console::WriteLine( MakeLine( 4, 7, "< " ) );
}
// 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
Version Information

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0, 2.0, 1.1

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

XNA Framework

Supported in: 3.0, 2.0, 1.0

.NET for Windows Phone apps

Supported in: Windows Phone 8.1, Windows Phone Silverlight 8.1, Windows Phone Silverlight 8

Portable Class Library

Supported in: Portable Class Library