String Join
In this chapter you will learn:
Use the Join() method to join strings
Join
method from string type is a static
method which concatenate an array of string with delimiter.
It does the opposite of Split method.
using System;/*from j ava2 s .c o m*/
class Sample
{
public static void Main()
{
string[] arr = new string[] { "JAVA", "2", "s", ".com" };
string s = string.Join(" ", arr);
Console.WriteLine(s);
}
}
The output:
Join string by |
using System;//from ja va 2 s .co m
public class MainClass
{
public static void Main()
{
string[] s = new string[] { "J", "M", "P", "C" };
string joined = String.Join("|", s);
Console.WriteLine(joined);
}
}
The code above generates the following result.
Next chapter...
What you will learn in the next chapter:
- How to split a string
- Use the Split() method to split strings
- Split with space
- Split with a list of dividers
- Split by char array
- Split a string delimited by another string and return 2 non-empty elements
- Split string with \\
Home » C# Tutorial » String