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
0
MichelleLacyAuthor Commented:
I am sorry, I meant ArrayList of type string
0
Mike TomlinsonMiddle School Assistant TeacherCommented:
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
0
Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

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

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

0

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.
 
0
Mike TomlinsonMiddle School Assistant TeacherCommented:
Like so:

            List<string> myList = new List<string>();
            myList.AddRange(this.textBox1.Lines);
0
Mike TomlinsonMiddle School Assistant TeacherCommented:
Hehe...like mwvisa1 already posted.  =)
0
Mike TomlinsonMiddle School Assistant TeacherCommented:
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".  =)
0
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);
0
MichelleLacyAuthor Commented:
Thanks for the help from everyone.  The answers were coming so quickly, but mwvisa1 was first to reply.
0
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.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.