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

Concatenates the specified 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, _
	value As String(), _
	startIndex As Integer, _
	count As Integer _
) As String


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.

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

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

Class Sample
   Public Shared Sub Main()
      Dim val As [String]() =  {"apple", "orange", "grape", "pear"}
      Dim sep As [String] = ", " 
      Dim result As [String]

      Console.WriteLine("sep = '{0}'", sep)
      Console.WriteLine("val() = {{'{0}' '{1}' '{2}' '{3}'}}", val(0), val(1), val(2), val(3))
      result = [String].Join(sep, val, 1, 2)
      Console.WriteLine("String.Join(sep, val, 1, 2) = '{0}'", result)
   End Sub 
End Class  
'This example displays the following output: 
'       sep = ', ' 
'       val() = {'apple' 'orange' 'grape' 'pear'} 
'       String.Join(sep, val, 1, 2) = 'orange, grape'

.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

Portable Class Library

Supported in: Portable Class Library

Supported in: Windows Phone 8.1

Supported in: Windows Phone Silverlight 8.1

Supported in: Windows Phone Silverlight 8
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
© 2015 Microsoft