This post will discuss how to split a string by a string delimiter in C#.

1. Using String.Split() method

The String.Split() method splits a string into substrings based on the strings in an array.

The following code example demonstrates how to use the String.Split() method to split a string using a string separator with StringSplitOptions.None to include empty array elements in the returned array.

Download  Run Code

2. Using Regex.Split() method

The Regex.Split() method is used to split an input string into an array of substrings at the positions defined by a regular expression match.

The following code example demonstrates how to use the Regex.Split() method to split a string using a string separator.

Download  Run Code

That’s all about splitting a string using a string delimiter in C#.