As an alternative, the following code can be used to split the string into separate words.
It first checks for
even number of double quotes
within the string.
It removes the
empty entries
generated by split.
It
trims
the words so that there is no extra space at the beginning and end of the word
string input = @" This is "" my string "" for ""searching in my "" program";
if (input.Count (ch => ch == '"') % 2 != 0)
Console.WriteLine ("Inadequate double quotes");
else {
List<string> elements = new List<string>();
string[] temp = input.Split('"');
for(int i=0; i<temp.Length; i++)
if (i%2==0)
elements.AddRange(temp[i].Split(new char[]{' '},
StringSplitOptions.RemoveEmptyEntries));
else if (temp[i].Trim() != string.Empty)
elements.Add(temp[i].Trim());
}