C# – Split a string with delimiter string

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

Reference to C# String.Split() method.

Examples

ADVERTISEMENT

1. Split string with with “mm” as delimiter string

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

C# Program

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

Output

apple
banana
cherry

Conclusion

In this C# Tutorial, we have learned how to split a given string with a specified delimiter string value, using String.Split() method.