How to Split a String in C#/CSharp

To split a string in C#/CSharp, we make use of Split method.  This will take a character as parameter to split.  In the below given example, we are passing an empty space as parameter.

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
using System;
namespace Hello_World
{
class Program
{
static void Main(string[] args)
{
string hello = "I love making tutorials.";
string[] multiple = hello.Split(' ');
foreach(string single in multiple)
{
Console.WriteLine(single);
}
}
}
}
using System; namespace Hello_World { class Program { static void Main(string[] args) { string hello = "I love making tutorials."; string[] multiple = hello.Split(' '); foreach(string single in multiple) { Console.WriteLine(single); } } } }
using System;

namespace Hello_World
{

    class Program
    {
        static void Main(string[] args)
        {
            string hello = "I love making tutorials.";

            string[] multiple = hello.Split(' ');

            foreach(string single in multiple)
            {
                Console.WriteLine(single);
            }           

        }               
    }
}