Click here to Skip to main content
15,879,613 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Form has two multiline text boxes and one button. I am using a foreach loop to read each word in a textbox and put the output for each word in a textbox called outputtextbox.text and append some data to it. The program works perfectly, except the output in the output textbox only gives me the last word from the input textbox. I set a breakpoint on the foreach and stepped through the code and I can see that each word is being read. However, the output is only displaying one word, the last word. Ie) (This is not real code)inputtextbox = bears cats dogs and user hits the submit button, only dogs with the appended text will be displayed. It's as if the output textbox is being overwritten. Can anyone please give me any pointers to display all the words on seperate lines in an output multiline textbox. Thank you so much. I would really apprecaiate the help. Also, should I use another approach?

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace ForEachTester
{
    public partial class ForEachForm : Form
    {
        public ForEachForm()
        {
            InitializeComponent();
        }

        string sentence = "";
        string SingleWordHolder = "";

        private void Submitbutton_Click(object sender, EventArgs e)
        {
                        
            sentence = InputtextBox.Text;
            
            foreach (string word in sentence.Split())
            {
                                
                SingleWordHolder = word;
                
                //supposed to append text and output each word on
                //on a seperate line in the output multiline text box. 
                OutputtextBox.Text = ("abo" + SingleWordHolder + "nvo");
            }          


        }
    }
}
Posted

1 solution

Did you even read the responses that you got in the forums? They clearly state the problem.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900