C# String Join(String, String[], Int32, Int32)

Description

String Join(String, String[], Int32, Int32) concatenates the specified elements of a string array, using the specified separator between each element.

Syntax

String.Join(String, String[], Int32, Int32) has the following syntax.


public static string Join(
  string separator,//w  ww . j  a v a  2  s  .c om
  string[] value,
  int startIndex,
  int count
)

Parameters

String.Join(String, String[], Int32, Int32) has the following parameters.

  • separator - The string to use as a separator. separator is included in the returned string only if value has more than one element.
  • value - An array that contains the elements to concatenate.
  • startIndex - The first element in value to use.
  • count - The number of elements of value to use.

Returns

String.Join(String, String[], Int32, Int32) method returns A string that consists of the strings in value delimited by the separator string. -or- String.Empty if count is zero, value has no elements, or separator and all the elements of value are String.Empty.

Example

Sample for String.Join(String, String[], int int)


/*from  www .jav a 2  s .  c  o  m*/
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);
    }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    System »




Array
BitConverter
Boolean
Byte
Char
Console
ConsoleKeyInfo
Convert
DateTime
DateTimeOffset
Decimal
Double
Enum
Environment
Exception
Guid
Int16
Int32
Int64
Math
OperatingSystem
Random
SByte
Single
String
StringComparer
TimeSpan
TimeZone
TimeZoneInfo
Tuple
Tuple
Tuple
Type
UInt16
UInt32
UInt64
Uri
Version