469,336 Members | 5,360 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,336 developers. It's quick & easy.

read a multiline textbox and store each line into an array (c#)

Hi there,

Can anyone help me out on this one? i want to read each line entered in a
multiline textbox and store it into an array. I cant find any properties for
this in the control, the only thing i can think of is to use Text.Split and
split the string at each carriage return,

Any help appreciated.
thanks.
Paul
Jan 9 '07 #1
7 45421
Take a look at the TextBox.Lines property. It gets/sets an array of strings
(as opposed to a StringArray)

Mike Ober.

"Milsnips" <mi******@hotmail.comwrote in message
news:ux**************@TK2MSFTNGP06.phx.gbl...
Hi there,

Can anyone help me out on this one? i want to read each line entered in a
multiline textbox and store it into an array. I cant find any properties
for this in the control, the only thing i can think of is to use
Text.Split and split the string at each carriage return,

Any help appreciated.
thanks.
Paul

Jan 9 '07 #2
Hi Mike,

only problem is im doing it in c# ASP.NET and .Lines property is not
available here, i think its only in Windows Forms.

regards,
Paul

"Michael D. Ober" <obermd.@.alum.mit.edu.nospamwrote in message
news:uk****************@TK2MSFTNGP02.phx.gbl...
Take a look at the TextBox.Lines property. It gets/sets an array of
strings (as opposed to a StringArray)

Mike Ober.

"Milsnips" <mi******@hotmail.comwrote in message
news:ux**************@TK2MSFTNGP06.phx.gbl...
>Hi there,

Can anyone help me out on this one? i want to read each line entered in a
multiline textbox and store it into an array. I cant find any properties
for this in the control, the only thing i can think of is to use
Text.Split and split the string at each carriage return,

Any help appreciated.
thanks.
Paul


Jan 9 '07 #3
Never mind, i found a solution using
System.Text.RegularExpressions.Regex.Split

It allows splitting by a string, instead of a char array.

regards,
Paul
"Michael D. Ober" <obermd.@.alum.mit.edu.nospamwrote in message
news:uk****************@TK2MSFTNGP02.phx.gbl...
Take a look at the TextBox.Lines property. It gets/sets an array of
strings (as opposed to a StringArray)

Mike Ober.

"Milsnips" <mi******@hotmail.comwrote in message
news:ux**************@TK2MSFTNGP06.phx.gbl...
>Hi there,

Can anyone help me out on this one? i want to read each line entered in a
multiline textbox and store it into an array. I cant find any properties
for this in the control, the only thing i can think of is to use
Text.Split and split the string at each carriage return,

Any help appreciated.
thanks.
Paul


Jan 9 '07 #4
Instead of using the regex split, you might want to use the string.Split
method - it's optimized for strings.

Mike.

"Milsnips" <mi******@hotmail.comwrote in message
news:Oe*************@TK2MSFTNGP02.phx.gbl...
Never mind, i found a solution using
System.Text.RegularExpressions.Regex.Split

It allows splitting by a string, instead of a char array.

regards,
Paul
"Michael D. Ober" <obermd.@.alum.mit.edu.nospamwrote in message
news:uk****************@TK2MSFTNGP02.phx.gbl...
>Take a look at the TextBox.Lines property. It gets/sets an array of
strings (as opposed to a StringArray)

Mike Ober.

"Milsnips" <mi******@hotmail.comwrote in message
news:ux**************@TK2MSFTNGP06.phx.gbl...
>>Hi there,

Can anyone help me out on this one? i want to read each line entered in
a multiline textbox and store it into an array. I cant find any
properties for this in the control, the only thing i can think of is to
use Text.Split and split the string at each carriage return,

Any help appreciated.
thanks.
Paul



Jan 9 '07 #5

Michael D. Ober wrote:
Instead of using the regex split, you might want to use the string.Split
method - it's optimized for strings.
Unless anybody knows of any reason why it should not be used in this
way, I find the following syntax works fine:

string a = (some string with newlines in it)
string[] b = a.Split(new string[] { Environment.NewLine},
StringSplitOptions.None);

http://msdn2.microsoft.com/en-us/library/tabh47cf.aspx

Jan 10 '07 #6
Milsnips wrote:
Never mind, i found a solution using
System.Text.RegularExpressions.Regex.Split

It allows splitting by a string, instead of a char array.
Another solution to try if you need to loop through the strings is a
StringReader.

Chris

Jan 10 '07 #7
Unless C# has the equivalant of the VB vbNewLine or the C/C++ '\n' character
strings, this should be the easiest way to split a string. I know that '\n'
is a character and not a string in C/C++. However, the framework's
string.split function takes both.

I would try replacing the second line with

string[] b = a.Split("\n");

If that doesn't work, try

string[] b = a.Split(Environment.Newline)

In either case, the string.Split method will work with a string or a
character.

Mike Ober.

"Bobbo" <ro************@choicequote.co.ukwrote in message
news:11**********************@77g2000hsv.googlegro ups.com...
>
Michael D. Ober wrote:
>Instead of using the regex split, you might want to use the string.Split
method - it's optimized for strings.

Unless anybody knows of any reason why it should not be used in this
way, I find the following syntax works fine:

string a = (some string with newlines in it)
string[] b = a.Split(new string[] { Environment.NewLine},
StringSplitOptions.None);

http://msdn2.microsoft.com/en-us/library/tabh47cf.aspx

Jan 10 '07 #8

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by Peter Nagel | last post: by
4 posts views Thread by Michael C | last post: by
1 post views Thread by Olav Tollefsen | last post: by
1 post views Thread by Flack | last post: by
4 posts views Thread by =?Utf-8?B?R2lkaQ==?= | last post: by
2 posts views Thread by Nathan Sokalski | last post: by
1 post views Thread by CARIGAR | last post: by
1 post views Thread by haryvincent176 | last post: by
1 post views Thread by Marylou17 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.