![]() |
VOOZH | about |
In C#, Split() is a string class method used to divide a string into an array of substrings. The Split() method divides a string into an array of substrings using specified delimiters.
The delimiters can be:
In simple words, it returns a string array that contains the substrings in the current instance that are delimited by elements of a specified string or Unicode character array.
Example: Separating a string based on space using String.Split() method.
Hello from GeeksforGeeks
Explanation: In the above example, we use the Split() method which converts the string into the string array based on a single space and then we print each string present in the array using the foreach loop.
These are the six overloads of String.Split() method.
| Methods | Description |
|---|---|
| Split(Char[]) | Splits a string into substrings using an array of characters as delimiters. |
| Split(Char[], StringSplitOptions) | Splits using character array, can include/exclude empty substrings. |
| Split(Char[], Int32) | Splits a string into substrings based on the array of characters. |
| Split(Char[], Int32, StringSplitOptions) | Splits using character array with a limit and option to remove empty entries. |
| Split(String[], StringSplitOptions) | Splits using string array as delimiters, can include/exclude empty substrings. |
Split(String[], Int32, StringSplitOptions) | Splits using string array with a limit and option to remove empty entries. |
Parameters:
Return Type: This method returns an array whose elements contain the substrings in this string which are delimited by one or more characters or an array of strings in the separator .
Exceptions:
This method is used to split a string into a maximum number of substrings based on the strings in an array. We can specify whether the substrings include empty array elements or not.
Syntax:
public String[] Split(String[] separator, int count, StringSplitOptions options);
Example: Separate the string using the Split(String[], Int32, StringSplitOptions) method.
Geeks For Geeks
This method is used to split a string into a maximum number of substrings based on the characters in an array passed on the argument and also we can pass the count of the maximum substring to return.
Syntax:
public String[] Split(char[] separator, int count, StringSplitOptions options);
Example:
Geeks For Geeks
This method is used to split a string into substrings based on the strings in an array. We can also specify whether the substrings include empty array elements or not.
Syntax:
public String[] Split(String[] separator, StringSplitOptions options);
Example:
Geeks For Geeks
This method is used to split a string into a maximum number of substrings based on the characters in an array. We can also specify the maximum number of substrings to return.
Syntax:
public String[] Split(char[] separator);
Example:
Geeks For Geeks
This method splits a string into substrings based on the characters in an array passed as a separator. We can also specify whether empty array elements should be included or not using the second parameter StringSplitOptions.
Syntax:
public String[] Split(char[] separator, StringSplitOptions option);
Example:
Geeks For Geeks
This method is used to splits the string into a maximum number of substrings based on the characters in an array passed as a seperator. We can also specify the maximum number of substrings which we want to return.
Syntax:
public String[] Split(char[] separator, int count);
Example:
Geeks For Geeks