How to split string in c#

How to split string in c#?

 

The String.Split method creates an array of substrings by splitting the input string based on one or more delimiters.

using System;
using System.Collections.Generic;

class Program
{
    static void Main()
    {
        Console.WriteLine("Comma separated strings");
        string sp = "aa aa, bb bb, cc cc, dd dd, Rak Singh";
        // Split authors separated by a comma followed by space  
        string[] splist = sp.Split(',');
        foreach (string splt in splist)
            Console.WriteLine(splt);  
        Console.ReadKey();
    }
}

 

using System;
using System.Collections.Generic;

class Program
{
    static void Main()
    {
        string phrase = "How to split string in c#";
        string[] words = phrase.Split(' ');

        foreach (var word in words)
        {
            System.Console.WriteLine(word);
         }  
          Console.ReadKey();
    }
}

2021-10-03