.NET Framework Class Library
StringJoin 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)
Syntax
Public Shared Function Join ( _
	separator As [%$TOPIC/tk0xe5h0_en-us_VS_110_1_0_0_0_0%], _
	value As [%$TOPIC/tk0xe5h0_en-us_VS_110_1_0_0_0_1%](), _
	startIndex As [%$TOPIC/tk0xe5h0_en-us_VS_110_1_0_0_0_2%], _
	count As [%$TOPIC/tk0xe5h0_en-us_VS_110_1_0_0_0_3%] _
) As [%$TOPIC/tk0xe5h0_en-us_VS_110_1_0_0_0_4%]
public static [%$TOPIC/tk0xe5h0_en-us_VS_110_1_0_1_0_0%] Join(
	[%$TOPIC/tk0xe5h0_en-us_VS_110_1_0_1_0_1%] separator,
	[%$TOPIC/tk0xe5h0_en-us_VS_110_1_0_1_0_2%][] value,
	[%$TOPIC/tk0xe5h0_en-us_VS_110_1_0_1_0_3%] startIndex,
	[%$TOPIC/tk0xe5h0_en-us_VS_110_1_0_1_0_4%] count
)
public:
static [%$TOPIC/tk0xe5h0_en-us_VS_110_1_0_2_0_0%]^ Join(
	[%$TOPIC/tk0xe5h0_en-us_VS_110_1_0_2_0_1%]^ separator, 
	array<[%$TOPIC/tk0xe5h0_en-us_VS_110_1_0_2_0_2%]^>^ value, 
	[%$TOPIC/tk0xe5h0_en-us_VS_110_1_0_2_0_3%] startIndex, 
	[%$TOPIC/tk0xe5h0_en-us_VS_110_1_0_2_0_4%] count
)
static member Join : 
        separator:[%$TOPIC/tk0xe5h0_en-us_VS_110_1_0_3_0_0%] * 
        value:[%$TOPIC/tk0xe5h0_en-us_VS_110_1_0_3_0_1%][] * 
        startIndex:[%$TOPIC/tk0xe5h0_en-us_VS_110_1_0_3_0_2%] * 
        count:[%$TOPIC/tk0xe5h0_en-us_VS_110_1_0_3_0_3%] -> [%$TOPIC/tk0xe5h0_en-us_VS_110_1_0_3_0_4%]
public static function Join(
	separator : [%$TOPIC/tk0xe5h0_en-us_VS_110_1_0_4_0_0%], 
	value : [%$TOPIC/tk0xe5h0_en-us_VS_110_1_0_4_0_1%][], 
	startIndex : [%$TOPIC/tk0xe5h0_en-us_VS_110_1_0_4_0_2%], 
	count : [%$TOPIC/tk0xe5h0_en-us_VS_110_1_0_4_0_3%]
) : [%$TOPIC/tk0xe5h0_en-us_VS_110_1_0_4_0_4%]

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.

startIndex
Type: SystemInt32

The first element in value to use.

count
Type: SystemInt32

The number of elements of value to use.

Return Value

Type: SystemString
A string that consists of the strings in value delimited by the separator string.
-or-
StringEmpty if count is zero, value has no elements, or separator and all the elements of value are StringEmpty.
Exceptions
ExceptionCondition
ArgumentNullException

value is .

ArgumentOutOfRangeException

startIndex or count is less than 0.

-or-

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

OutOfMemoryException

Out of memory.

Remarks

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

Examples

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'
// Sample for String.Join(String, String[], int int) 
using System;

class Sample {
    public static void Main() {
    String[] val = {"apple", "orange", "grape", "pear"};
    String sep   = ", ";
    String result;

    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);
    }
}
/*
This example produces the following results:
sep = ', '
val[] = {'apple' 'orange' 'grape' 'pear'}
String.Join(sep, val, 1, 2) = 'orange, grape'
*/
// Sample for String::Join(String, String[], int int) 
using namespace System;
int main()
{
   array<String^>^val = {"apple","orange","grape","pear"};
   String^ sep = ", ";
   String^ result;
   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 );
}

/*
This example produces the following results:
sep = ', '
val[] = {'apple' 'orange' 'grape' 'pear'}
String::Join(sep, val, 1, 2) = 'orange, grape'
*/
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