Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

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

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)

public static string Join (
	string separator,
	string[] value,
	int startIndex,
	int count
)
public static String Join (
	String separator, 
	String[] value, 
	int startIndex, 
	int count
)
public static function Join (
	separator : String, 
	value : String[], 
	startIndex : int, 
	count : int
) : String
Not applicable.

Parameters

separator

A String.

value

An array of String.

startIndex

The first array element in value to use.

count

The number of elements of value to use.

Return Value

A String object consisting of the strings in value joined by separator. Or, Empty if count is zero, value has no elements, or separator and all the elements of value are Empty.

Exception typeCondition

ArgumentNullException

value is a null reference (Nothing in Visual Basic).

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.

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 a null reference (Nothing in Visual Basic), the empty string (Empty) 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)
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)
import System.*;

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

        Console.WriteLine("sep = '{0}'", sep);
        Console.Write("val[] = {{'{0}' '{1}'", val.get_Item(0), val.get_Item(1));
        Console.WriteLine(" '{0}' '{1}'}}", val.get_Item(2), val.get_Item(3));
        result = String.Join(sep, val, 1, 2);
        Console.WriteLine("String.Join(sep, val, 1, 2) = '{0}'", result);
    } //main
} //Sample
/*
This example produces the following results:
sep = ', '
val[] = {'apple' 'orange' 'grape' 'pear'}
String.Join(sep, val, 1, 2) = 'orange, grape'
*/

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0, 1.0

XNA Framework

Supported in: 1.0
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

Show:
© 2014 Microsoft