For example, take the string "Shut downproblem in windows 8". How can I split the string by a space and access the words as keyword which should return "Shut","down","problem","in","windows","8".
class TestStringSplit
{
staticvoid Main()
{
char[] delimiterChars = { ' ', ',', '.', ':', '\t' };
string text = "one\ttwo three:four,five six seven";
System.Console.WriteLine("Original text: '{0}'", text);
string[] words = text.Split(delimiterChars);
System.Console.WriteLine("{0} words in text:", words.Length);
foreach (string s in words)
{
System.Console.WriteLine(s);
}
// Keep the console window open in debug mode.
System.Console.WriteLine("Press any key to exit.");
System.Console.ReadKey();
}
}
/* Output:
Original text: 'one two three:four,five six seven'
7 words in text:
one
two
three
four
five
six
seven
*/
We use cookies to ensure you have the best browsing experience on our website. By using our site, you
acknowledge that you have read and understood our
Cookie Policy &
Privacy Policy.
string[] keywords = txtValue.Text.Trim().Split(new string[] { " " },StringSplitOptions.RemoveEmptyEntries);