What is the usage of the split function in C#?
In C#, the Split function is used to split a string based on a specified delimiter and returns a string array. The syntax is as follows:
public string[] Split(params char[] separator)
The parameter params char[] separator represents an array of characters to be used in splitting the string. It can specify one or more characters as separators.
For example, you can use the Split function to split a space-separated string into an array of words.
string text = "Hello World";
string[] words = text.Split(' ');
foreach (string word in words)
{
Console.WriteLine(word);
}
The code above will output:
Hello
World