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.
MichelleLacyAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Fernando SotoRetiredCommented:
This should do it.

String[] myStringArray = textBox1.Lines;

Fernando
MichelleLacyAuthor Commented:
I am sorry, I meant ArrayList of type string
Mike TomlinsonHigh School Computer Science, Computer Applications, and Mathematics TeachersCommented:
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
CompTIA Network+

Prepare for the CompTIA Network+ exam by learning how to troubleshoot, configure, and manage both wired and wireless networks.

Kevin CrossChief Technology OfficerCommented:
You can try the AddRange function.

List<string> list = new List<string>();
list.AddRange(textBox1.Lines);

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
MichelleLacyAuthor Commented:
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.
 
Mike TomlinsonHigh School Computer Science, Computer Applications, and Mathematics TeachersCommented:
Like so:

            List<string> myList = new List<string>();
            myList.AddRange(this.textBox1.Lines);
Mike TomlinsonHigh School Computer Science, Computer Applications, and Mathematics TeachersCommented:
Hehe...like mwvisa1 already posted.  =)
Mike TomlinsonHigh School Computer Science, Computer Applications, and Mathematics TeachersCommented:
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".  =)
Fernando SotoRetiredCommented:
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);
MichelleLacyAuthor Commented:
Thanks for the help from everyone.  The answers were coming so quickly, but mwvisa1 was first to reply.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.