简体   繁体   English

如何在文本框中显示字符串数组?

[英]How can I display a string array in a textbox?

private void SplitString()
{
    ArrayList splitted = new ArrayList();

    string[] words = richTextBox1.Text.Split(new char [] { ' ' },
    StringSplitOptions.RemoveEmptyEntries);

    var word_query =
        (from string word in words
         orderby word
         select word).Distinct();

    string[] result = word_query.ToArray();

    foreach(string results in result)
    {
        richTextBox2.Text = results;
    }         
}

I wrote a form application for taking a text file and splitting strings at the file. 我编写了一个表单应用程序,用于获取文本文件并在该文件处拆分字符串。 And the final purpose is writing unique strings on textbox. 最后的目的是在文本框中编写唯一的字符串。 The problem is strings flow quickly on textbox but i like to stand them on textbox. 问题是字符串在文本框上快速流动,但我希望它们在文本框上站立。

You are iterating your array and assigning each time so textbox will have only last item of the array. 您要遍历数组并每次分配一次,因此文本框将只有数组的最后一项。

You just to join your array and display in the textbox in following way : 您只需按照以下方式加入数组并显示在文本框中:

string[] result = word_query.ToArray();
richTextBox2.Text = String.Join(",",result); // You can use any string as separator.

如果希望每个字符串在文本框中都显示在单独的行上,只需将字符串数组分配给Lines属性,如下所示:

richTextBox2.Lines = result;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM