How to split a string by a substring delimiter in C#

1 Answer

0 votes
using System;

class Program
{
    static void Main(string[] args)
    {
        string str = "Apples and Oranges and Bananas and Grapes are tasty";
        string delimiter = "and";

        // Split the string by the delimiter
        string[] parts = str.Split(new string[] { delimiter }, StringSplitOptions.None);

        foreach (string part in parts) {
            Console.WriteLine(part.Trim());
        }
    }
}




/*
run:

Apples
Oranges
Bananas
Grapes are tasty

*/

 



answered Aug 11, 2025 by avibootz

Related questions

...