C# Split Articles

You can split strings in your C# program to isolate and extract substrings with a single function call. Many programs that process text data will need to split strings; fortunately, this site introduces several articles on Split methods.

Split introduction

To start, this simple program shows how you can split an input string on the comma delimiter character. Then, the resulting array is enumerated in the foreach loop. For more examples, see the linked article after the example.

--- Program that uses Split method [C#] ---

using System;

class Program
{
    static void Main()
    {
        string input = "one,two,three";
        string[] parts = input.Split(',');
        foreach (string part in parts)
            Console.WriteLine(part);
    }
}

--- Output of the program ---

one
two
three

Split examples. This is the most popular article about splitting strings on the site, and it contains the most information and useful tips. I recommend visiting it first and then checking the less popular articles on this page.

See Split String Examples.

Regex.Split method

The Regex.Split method is more powerful than the string.Split method; it is also somewhat less efficient in many cases. For complete tutorials on this version of Split, please see the linked article.

See Regex.Split Method Examples.

Exploding strings

This article details an interesting extension method that lets you separate a large string into several substrings of a certain length. In some languages, splitting a string results uses this logic.

See Explode String Extension Method.

Using StringSplitOptions

With the string.Split method, you can specify a StringSplitOptions enumerated constant. The example linked here provides an example for how you can use this option as an argument.

See StringSplitOptions Enumeration.

Misc. articles

There are a few more articles about splitting strings also available on this site. These are supplementary articles and may not be extremely useful for many people.

See PHP Explode Function.

See Split Delimiter Use.

See Split Method and Escape Characters.

See Split String Improvement.

© 2007-2010 Sam Allen. All rights reserved.

Dot Net Perls  Sam Allen