TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
squire long
NA
3
0
Multiline textbox output using a foreach
Jan 26 2010 9:14 PM
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.
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");
}
}
}
}
Reply
Answers (
6
)
how to display common items in two list views in a third list view??
connection with ms access 2007 with datagrid in C#