472,345 Members | 1,533 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,345 software developers and data experts.

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 45628
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Peter Nagel | last post by:
I would like to insert some strings in a multiline TextBox. At the time of inserting the TextBox already contains some strings each in a separate...
4
by: Michael C | last post by:
Hi all, I'm trying to add lines to a multiline textbox. Here's what I'd like to end up with in the textbox (as an example): Line1 Line2...
1
by: Olav Tollefsen | last post by:
I have added a MultiLine TextBox to my aspx page: <asp:TextBox ID="TextBox1" runat="server" BorderStyle="None" ReadOnly="True"...
1
by: Flack | last post by:
Hey guys, I have two questions regarding the vertical srollbar of a multiline textbox. 1. I have an "Ok" button that is initially disabled. I...
2
by: Mike | last post by:
I am trying to write a little program for my own use using VB2005 express edition. I have a list of peoples names in a file that I read into an...
7
by: Anil Gupte | last post by:
I have read a lot about getting lines from a multiline textbox in VB.Net. However, I cannot for the life of me figure out how to write to a...
4
by: =?Utf-8?B?R2lkaQ==?= | last post by:
Hi, In multiLine textBox, enter moves to the next line, how can i overwrite it, so enter will move to the next control and ctrl + enter will move...
2
by: Nathan Sokalski | last post by:
I have a multiline TextBox that I want to display the text used to create a control in an apsx file. I want each of these to be on a separate line...
10
by: JohannKotzeVet | last post by:
Good day! I have a form in Access that has a multiple line textbox (I called it cAbnormalities). This text box is populated by the user ONLY...
0
by: concettolabs | last post by:
In today's business world, businesses are increasingly turning to PowerApps to develop custom business applications. PowerApps is a powerful tool...
0
by: teenabhardwaj | last post by:
How would one discover a valid source for learning news, comfort, and help for engineering designs? Covering through piles of books takes a lot of...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
2
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.