---
title: "Split string in C#"  
description: "Split string in C#"  
author: "Samuel Fernandes"  
published: 2013-02-06  
updated: 2013-02-09  
canonical: https://www.mindstick.com/forum/581/split-string-in-c-sharp  
category: "c#"  
tags: ["c#"]  
reading_time: 2 minutes  

---

# Split string in C#

Using C#, how do I [split](https://www.mindstick.com/blog/11920/top-3-voltas-split-acs-for-your-home) a [string](https://www.mindstick.com/articles/1527/string-split-in-c-sharp) so I can [access](https://www.mindstick.com/articles/12994/how-foreigners-can-access-blocked-websites-in-china) words as [keyword](https://www.mindstick.com/forum/33572/sql-inner-join-keyword)\
For example, take the string "[Shut down](https://answers.mindstick.com/qa/108505/what-to-do-if-your-computer-won-t-shut-down) [problem](https://yourviews.mindstick.com/view/81399/tackling-the-problem-of-unemployment-during-corona-pandemic) in [windows](https://www.mindstick.com/articles/311752/how-to-install-and-use-the-google-wifi-software-on-a-windows-or-mac-computer) 8". How can I split the string by a [space](https://www.mindstick.com/articles/12954/do-your-electrical-repair-in-your-own-space) and access the words as keyword which should return "Shut","down","problem","in","windows","8".Please help me!\
Thanks

## Replies

### Reply by Anonymous User

```
class TestStringSplit
{
    static void 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
 */
```

### Reply by Shankar M

Try this,\
Hope this might help you Solve it.\
string txt = "Shut down problem in windows 8"; string[] splitstring = txt.Split(' '); foreach (string s in splitstring) { MessageBox.Show(s.ToString()); } \
Thanks,Shankar

### Reply by AVADHESH PATEL

Hi Samuel!\
Use below line of code, that split string into words\

```
string[] keywords = txtValue.Text.Trim().Split(new string[] { " " },StringSplitOptions.RemoveEmptyEntries);
```

\
If you want to hold all words in list then use as below\

```
protected List<string> keywords = new List<string>();this.keywords = keywords.ToList();
```


---

Original Source: https://www.mindstick.com/forum/581/split-string-in-c-sharp

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
