How to use C# string Split
C# Split() handles splitting upon given string and character delimiters. It returns an array of String containing the substrings delimited by the given System.Char array.

If your String contains "dd-mm-yy", split on the "-" character to get an array of: "dd" "mm" "yy".
The String Split method ignores any element of separator whose value is null or the empty string ("").
Syntax :
- Separator - the given delimiter
- An array of Strings delimited by one or more characters in separator.
Output:
C# String Split Example
How to split strings using regular expressions
The Regular Expressions Split() methods are almost similar to the String.Split() method, except that Regex.Split() method splits the string at a delimiter determined by a Regular Expression instead of a set of characters.
When using Regular Expressions you should use the following namespace in your project.
Output:
c# String Split by multiple characters delimiter
We can split a string by multiple character delimiter using String.split() method.
Output:
Using Regular Expressions for multiple characters
C# String Split by multiple characters delimiter using Regular Expressions
Output:
C# String split New Line
You can split a string on a new line or carriage return using the delimiter "\r\n".
C# String split Carriage Return
Output:
Environment.NewLine
Also you can use Environment.NewLine to remove the new line from a string
Output:
You can retrieve the result of a String splt() method to a C# List. The following program convert the String Array to a List.
C# Convert List to String
C# String split White spaces
StringSplitOptions.RemoveEmptyEntries guarantees the return value does not include array elements that contain an empty string. The following C# program shows how to remove all white spaces from string using StringSplitOptions.RemoveEmptyEntries.
Full Source C#When you execute this C# program you will get the result removing all white spaces from the string
- How to use C# string Clone
- How to use C# string Compare
- How to use C# string Concat
- How to use C# string Contains
- How to use C# string Copy
- How to use C# string CopyTo
- How to use C# string EndsWith
- How to use C# string Equals
- How to use C# string Format
- How to use C# string IndexOf
- How to use C# string Insert
- How to use C# string Length
- How to use C# string Substring
- How to validate a string using TryParse in C#
- How to C# String Null
- Generate random strings, alphanumeric strings and numbers