Windows apps
Collapse the table of content
Expand the table of content
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

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

Overload List

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

Supported by the .NET Compact Framework.

[Visual Basic] Overloads Public Shared Function Join(String, String()) As String
[C#] public static string Join(string, string[]);
[C++] public: static String* Join(String*, String*[]);
[JScript] public static function Join(String, String[]) : String;

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.

Supported by the .NET Compact Framework.

[Visual Basic] Overloads Public Shared Function Join(String, String(), Integer, Integer) As String
[C#] public static string Join(string, string[], int, int);
[C++] public: static String* Join(String*, String*[], int, int);
[JScript] public static function Join(String, String[], int, int) : String;

Example

[Visual Basic, C#, C++] Note   This example shows how to use one of the overloaded versions of Join. For other examples that might be available, see the individual overload topics.
[Visual Basic] 
' Sample for String.Join(String, String[], int int)
Imports System
 _

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 'Main
End Class 'Sample
'
'This example produces the following results:
'sep = ', '
'val() = {'apple' 'orange' 'grape' 'pear'}
'String.Join(sep, val, 1, 2) = 'orange, grape'
'

[C#] 
// 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'
*/

[C++] 
// Sample for String::Join(String, String[], int int)
#using <mscorlib.dll>

using namespace System;

int main() {
    String* val[] = {S"apple", S"orange", S"grape", S"pear"};
    String* sep   = S", ";
    String* result;

    Console::WriteLine(S"sep = '{0}'", sep);
    Console::WriteLine(S"val[] = {{'{0}' '{1}' '{2}' '{3}'}}", val[0], val[1], val[2], val[3]);
    result = String::Join(sep, val, 1, 2);
    Console::WriteLine(S"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'
*/

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

See Also

String Class | String Members | System Namespace

Show:
© 2016 Microsoft