String Split in C#


using System;

class Program
{
    static void Main()
    {
       string s = "there is a cat";
       //
       // Split string on spaces.
       // ... This will separate all the words.
       //
       string[] words = s.Split(' ');
       foreach (string word in words)
       {
           Console.WriteLine(word);
       }
    }
}

Output:

there
is
a
cat

using System;
using System.Text.RegularExpressions;

class Program
{
    static void Main()
    {
       string value = "cat\r\ndog\r\nanimal\r\nperson";
       //
       // Split the string on line breaks.
       // ... The return value from Split is a string[] array.
       //
       string[] lines = Regex.Split(value, "\r\n");

       foreach (string line in lines)
       {
           Console.WriteLine(line);
       }
    }
}

Output:
cat
dog
animal
person