String.Join Method (String, String(), Int32, Int32)

Updated: January 2011

Concatenates a specified separator String between each element of a specified String array, yielding a single concatenated string. Parameters specify the first array element and number of elements to use.

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

<SecuritySafeCriticalAttribute> _
Public Shared Function Join ( _
	separator As String, _
	value As String(), _
	startIndex As Integer, _
	count As Integer _
) As String


Type: System.String
The string to use as a separator.
Type: System.String()
An array that contains the elements to concatenate.
Type: System.Int32
The first element in value to use.
Type: System.Int32
The number of elements in value to use.

Return Value

Type: System.String
A string that consists of the strings in value delimited by the separator string.
String.Empty if count is zero, value has no elements, or separator and all the elements of value are String.Empty.


value is Nothing.


startIndex or count is less than 0.


startIndex plus count is greater than the number of elements in value.


Out of memory.

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

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

The following code example concatenates two elements from an array of names of fruit.

' Sample for String.Join(String, String[], int int)

Class Example

   Public Shared Sub Demo(ByVal outputBlock As System.Windows.Controls.TextBlock)
      Dim val As [String]() = {"apple", "orange", "grape", "pear"}
      Dim sep As [String] = ", "
      Dim result As [String]

      outputBlock.Text += String.Format("sep = '{0}'", sep) & vbCrLf
      outputBlock.Text += String.Format("val() = {{'{0}' '{1}' '{2}' '{3}'}}", val(0), val(1), val(2), val(3)) & vbCrLf
      result = [String].Join(sep, val, 1, 2)
      outputBlock.Text += String.Format("String.Join(sep, val, 1, 2) = '{0}'", result) & vbCrLf
   End Sub 'Main
End Class 'Sample
'This example produces the following results:
'sep = ', '
'val() = {'apple' 'orange' 'grape' 'pear'}
'String.Join(sep, val, 1, 2) = 'orange, grape'


Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

XNA Framework

Supported in: Xbox 360, Windows Phone OS 7.0

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.




January 2011

Noted that an empty string is substituted for any null element in the array.

Customer feedback.

Community Additions