String Join() method

CsharpProgrammingServer Side Programming

The Join () method in strings concatenates all the elements of a string array, using the specified separator between each element.

In the below example we have a multi-line string and we have set the separator as “\n” −

String.Join("\n", starray);


The following is the complete example −

 Live Demo

using System;

namespace StringApplication {

   class StringProg {
      static void Main(string[] args) {
         string[] starray = new string[]{"Down the way nights are dark",
            "And the sun shines daily on the mountaintop",
            "I took a trip on a sailing ship",
            "And when I reached Jamaica",
            "I made a stop"};

         string str = String.Join("\n", starray);


Down the way nights are dark
And the sun shines daily on the mountain top
I took a trip on a sailing ship
And when I reached Jamaica
I made a stop
Updated on 27-Mar-2020 09:40:42