Link to home
Start Free TrialLog in
Avatar of MichelleLacy
MichelleLacy

asked on

MultiLine Textbox to StringArray

How do I add lines from a multi-line text box to a string array.  Each line would represent an item in the array.
Avatar of Fernando Soto
Fernando Soto
Flag of United States of America image

This should do it.

String[] myStringArray = textBox1.Lines;

Fernando
Avatar of MichelleLacy
MichelleLacy

ASKER

I am sorry, I meant ArrayList of type string
An ArrayList of Type String?  ArrayList are not strongly typed!  They accept Object.

If you want a strongly typed collection then use List<>:
http://msdn.microsoft.com/en-us/library/6sh2ey19.aspx
ASKER CERTIFIED SOLUTION
Avatar of Kevin Cross
Kevin Cross
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
so if I used List<string> myList.  How would I add the lines from a multi-line text box?
myList.Add(textbox) would add the whole text box and I want each line to be an item.
 
Like so:

            List<string> myList = new List<string>();
            myList.AddRange(this.textBox1.Lines);
Hehe...like mwvisa1 already posted.  =)
It is technically possible with ArrayList:
(and looks the same)

            ArrayList myList = new ArrayList();
            myList.AddRange(this.textBox1.Lines);

            foreach (string line in myList)
            {
                System.Diagnostics.Debug.Print(line);
            }

It's just not as "correct".  =)
Although ArrayList is not a strongly typed array you can still add the line from the text box like so:

            ArrayList myStringArray = new ArrayList();
            myStringArray.AddRange(textBox1.Lines);
Thanks for the help from everyone.  The answers were coming so quickly, but mwvisa1 was first to reply.