C# Split a string with multiple string delimiters

To split a String with multiple delimiter strings in C#, call Split() on the string instance and pass the delimiter strings array as argument to this method. The method returns a String array with the splits.

Reference to C# String.Split() method.

Example

In the following C# program, we will take a string "abmmcdvvefgmmhi" and split this string with "mm" and "vv" as delimiter strings using String.Split(String[]) method.

C# Program

using System;
  
class Example {
    static void Main(string[] args) {
        String str = "abmmcdvvefgmmhi";
        String[] delimiters = {"mm", "vv"};
        String[] result = str.Split(delimiters, StringSplitOptions.None);
        for (int i = 0; i < result.Length; i++) {
            Console.WriteLine(result[i]);
        }
    }
}

Output

ab
cd
efg
hi
ADVERTISEMENT

Conclusion

In this C# Tutorial, we have learned how to split a given string with multiple strings as delimiters, using String.Split() method.