带foreach的多行文本框输出 [英] Multiline textbox output with a foreach

查看:195
本文介绍了带foreach的多行文本框输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

窗体具有两个多行文本框和一个按钮.我正在使用一个foreach循环来读取文本框中的每个单词,并将每个单词的输出放在一个名为outputtextbox.text的文本框中,并向其中添加一些数据.该程序运行完美,只是输出文本框中的输出仅使我输入文本框中的字词没有变化.我在foreach上设置了一个断点,并逐步浏览了代码,可以看到每个单词都在被读取.但是,输出仅显示一个单词,即最后一个单词.即(这不是真实的代码)inputtextbox =熊猫狗,用户单击提交按钮,仅显示带有附加文本的狗.就像输出文本框被覆盖一样.任何人都可以给我任何指针,以在输出多行文本框中的所有行上显示所有单词.太感谢了.我真的很感谢您的帮助.另外,我应该使用另一种方法吗?

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");
            }          


        }
    }
}

推荐答案

您甚至没有阅读您在论坛中获得的回复?他们清楚地指出了问题所在.
Did you even read the responses that you got in the forums? They clearly state the problem.


这篇关于带foreach的多行文本框输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆