Skip to main content

Get List of Words in a TextBox using C#


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:

output

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. }

Explanation:

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.

Output:

output

Best Regards,

Engr. Lyndon R. Bermoy
IT Instructor/System Developer/Android Developer
Mobile: 09079373999
Telephone: 826-9296
E-mail:[email protected]

Visit and like my page on Facebook at: https://www.facebook.com/BermzISware

Subscribe at my YouTube Channel at: Ser Bermz

Visit my website at: www.campcodes.com

Note: Due to the size or complexity of this submission, the author has submitted it as a .zip file to shorten your download time. After downloading it, you will need a program like Winzip to decompress it.

Virus note: All files are scanned once-a-day by SourceCodester.com for viruses, but new viruses come out every day, so no prevention program can catch 100% of them.

FOR YOUR OWN SAFETY, PLEASE:

1. Re-scan downloaded files using your personal virus checker before using it.
2. NEVER, EVER run compiled files (.exe's, .ocx's, .dll's etc.)--only run source code.

Add new comment

CAPTCHA
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.