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.
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
If you want a strongly typed collection then use List<>:
http://msdn.microsoft.com/en-us/library/6sh2ey19.aspx
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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.
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.textB ox1.Lines) ;
List<string> myList = new List<string>();
myList.AddRange(this.textB
Hehe...like mwvisa1 already posted. =)
It is technically possible with ArrayList:
(and looks the same)
ArrayList myList = new ArrayList();
myList.AddRange(this.textB ox1.Lines) ;
foreach (string line in myList)
{
System.Diagnostics.Debug.P rint(line) ;
}
It's just not as "correct". =)
(and looks the same)
ArrayList myList = new ArrayList();
myList.AddRange(this.textB
foreach (string line in myList)
{
System.Diagnostics.Debug.P
}
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(tex tBox1.Line s);
ArrayList myStringArray = new ArrayList();
myStringArray.AddRange(tex
ASKER
Thanks for the help from everyone. The answers were coming so quickly, but mwvisa1 was first to reply.
String[] myStringArray = textBox1.Lines;
Fernando