Skip to main content

Get List of Words in a TextBox using C#

Screenshot
Body
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 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: https://www.facebook.com/donzzsky Visit and like my page on Facebook at: https://www.facebook.com/BermzISware

Add new comment