Get List of Words in a TextBox using C#

Submitted by: 
Visitors have accessed this post 399 times.

In this tutorial, we will make a program that can get a list of words in a textbox or I mean retrieving each word one by one.

Now, let's start this tutorial!

1. Let's start with creating a Windows Form Application in C# for this tutorial by following the following steps in Microsoft Visual Studio 2010: Go to File, click New Project, and choose Windows Application.

2. Next, add one textbox named TextBox1, button named Button1, and a lisview named ListView1. You must design your interface like this:


3. Now put this code for your code module. This code is for Button1_Click. This will trigger to get the words one by one in your inputted text in the TextBox1.

  1. private void Button1_Click(System.Object sender, System.EventArgs e)
  2. {
  3. string[] texts = null;
  4. char[] spacing = new char[] {' '};
  5. texts = TextBox1.Text.Split(spacing);
  6. string word = default(string);
  7. foreach (string tempLoopVar_word in texts)
  8. {
  9. word = tempLoopVar_word;
  10. ListBox1.Items.Add(word);
  11. }
  12. }


We have initialized variable texts as a String,variable spacing as character that will hold the spacing and variable word as string. Next, we put a value to our variable texts to split the words in Textbox1 and then create a spacing in that. We have also created a For Each loop to find the words in the variable texts that holds the split words in the inputted texts of Textbox1. Then the word variable which holds now the split words of Textbox1 will be displayed in our ListView1.



Best Regards,

Engr. Lyndon Bermoy
IT Instructor/System Developer/Android Developer/Freelance Programmer

If you have some queries, feel free to contact the number or e-mail below.
Mobile: 09488225971
Landline: 826-9296
E-mail:[email protected]

Add and Follow me on Facebook:

Visit and like my page on Facebook at:

Add new comment

Filtered HTML

  • Web page addresses and e-mail addresses turn into links automatically.
  • You may insert videos with [video:URL]
  • Allowed HTML tags: <a> <em> <strong> <cite> <blockquote> <code> <ul> <ol> <li> <dl> <dt> <dd> <table> <tr> <td> <th> <img> <h1> <h2> <h3> <iframe> [video]
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>, <asp>, <c>, <cpp>, <csharp>, <css>, <html4strict>, <java>, <javascript>, <mysql>, <php>, <python>, <sql>, <vb>, <vbnet>. The supported tag styles are: <foo>, [foo].
  • Lines and paragraphs break automatically.

Plain text

  • No HTML tags allowed.
  • Lines and paragraphs break automatically.
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.