char[] charSeparators = new char[] { ' ' };
string[] wordSearched =
myText.Split(charSeparators, StringSplitOptions.RemoveEmptyEntries);
Now the Output will be:
------------------------
string 0 : This
string 1 : is
string 2 : the
string 3 : StringSplitOptions
string 4 : demo
String.Split method is overloaded and String.Split(Char[], StringSplitOptions) is one of them.
The first parameter is an array of Unicode characters that delimits the substrings in this string and second parameter decides whether to return a empty element or not.
Specify the None value to invoke the default behavior of the Split method, which is to return an array of both empty and that are not empty. Specify the RemoveEmptyEntries value to cause the Split method to return an array consisting solely of substrings that are not empty.