Get List of Words in a TextBox using C#
Submitted by donbermoy on Saturday, July 19, 2014 - 12:23.
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.
- private void Button1_Click(System.Object sender, System.EventArgs e)
- {
- string[] texts = null;
- texts = TextBox1.Text.Split(spacing);
- string word = default(string);
- foreach (string tempLoopVar_word in texts)
- {
- word = tempLoopVar_word;
- ListBox1.Items.Add(word);
- }
- }
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:
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/BermzISwareAdd new comment
- 146 views