String.Join Method (String, String())

Updated: January 2011

Concatenates a specified separator String between each element of a specified String array, yielding a single concatenated string.

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

'Declaration
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.
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.

ExceptionCondition
ArgumentNullException

value is Nothing.

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

The following example demonstrates the Join method.



Public Class Example

   Public Shared Sub Demo(ByVal outputBlock As System.Windows.Controls.TextBlock)

      outputBlock.Text += String.Format(MakeLine(0, 5, ", ")) & vbCrLf
      outputBlock.Text += String.Format(MakeLine(1, 6, "  ")) & vbCrLf
      outputBlock.Text += String.Format(MakeLine(9, 9, ": ")) & vbCrLf
      outputBlock.Text += String.Format(MakeLine(4, 7, "< ")) & vbCrLf
   End Sub 'Main


   Private Shared Function MakeLine(ByVal initVal As Integer, ByVal multVal As Integer, ByVal 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


Silverlight

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.

Date

History

Reason

January 2011

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

Customer feedback.

Community Additions

ADD
Show: