?
Solved

MultiLine Textbox to StringArray

Posted on 2008-11-10
10
Medium Priority
?
1,455 Views
Last Modified: 2013-12-17
How do I add lines from a multi-line text box to a string array.  Each line would represent an item in the array.
0
Comment
Question by:MichelleLacy
  • 4
  • 3
  • 2
  • +1
10 Comments
 
LVL 64

Expert Comment

by:Fernando Soto
ID: 22923904
This should do it.

String[] myStringArray = textBox1.Lines;

Fernando
0
 

Author Comment

by:MichelleLacy
ID: 22923918
I am sorry, I meant ArrayList of type string
0
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 22923968
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
Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

 
LVL 60

Accepted Solution

by:
Kevin Cross earned 2000 total points
ID: 22923980
You can try the AddRange function.

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

0
 

Author Comment

by:MichelleLacy
ID: 22923983
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
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 22923991
Like so:

            List<string> myList = new List<string>();
            myList.AddRange(this.textBox1.Lines);
0
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 22924000
Hehe...like mwvisa1 already posted.  =)
0
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 22924028
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
 
LVL 64

Expert Comment

by:Fernando Soto
ID: 22924033
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
 

Author Closing Comment

by:MichelleLacy
ID: 31515149
Thanks for the help from everyone.  The answers were coming so quickly, but mwvisa1 was first to reply.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question