begumes
begumes

Reputation: 9

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.

Upvotes: 0

Views: 2950

Answers (2)

Akash KC
Akash KC

Reputation: 16310

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.

Upvotes: 3

Mark Benningfield
Mark Benningfield

Reputation: 2912

If you want each string to appear in the text box on a separate line, just assign the array of strings to the Lines property, like so:

richTextBox2.Lines = result;

Upvotes: 1

Related Questions