How to split a string with multiple separators in C#

1 Answer

0 votes
using System;

class SplitExample
{
    static void Main()
    {
        string input = "abc,defg;hijk|lmnop-qrst_uvwxyz";
        // Use a regular expression to split on multiple delimiters
        string[] result = System.Text.RegularExpressions.Regex.Split(input, "[,;|\\-_]");

        foreach (string word in result)
        {
            Console.WriteLine(word);
        }
    }
}



/*
run:

abc
defg
hijk
lmnop
qrst
uvwxyz

*/

 



answered Jul 21, 2025 by avibootz
...