473,796 Members | 2,465 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 45815
Take a look at the TextBox.Lines property. It gets/sets an array of strings
(as opposed to a StringArray)

Mike Ober.

"Milsnips" <mi******@hotma il.comwrote in message
news:ux******** ******@TK2MSFTN GP06.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.nospamw rote in message
news:uk******** ********@TK2MSF TNGP02.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******@hotma il.comwrote in message
news:ux******** ******@TK2MSFTN GP06.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.Reg ularExpressions .Regex.Split

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

regards,
Paul
"Michael D. Ober" <obermd.@.alum. mit.edu.nospamw rote in message
news:uk******** ********@TK2MSF TNGP02.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******@hotma il.comwrote in message
news:ux******** ******@TK2MSFTN GP06.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******@hotma il.comwrote in message
news:Oe******** *****@TK2MSFTNG P02.phx.gbl...
Never mind, i found a solution using
System.Text.Reg ularExpressions .Regex.Split

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

regards,
Paul
"Michael D. Ober" <obermd.@.alum. mit.edu.nospamw rote in message
news:uk******** ********@TK2MSF TNGP02.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******@hotma il.comwrote in message
news:ux******* *******@TK2MSFT NGP06.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.New Line},
StringSplitOpti ons.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.Reg ularExpressions .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(Environ ment.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.goog legroups.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.New Line},
StringSplitOpti ons.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
2637
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 line. The new lines should be inserted somewhere in the middle of the existing lines moving some line to higher indices of the Lines property. What would be a good solution for my little problem? Greetings from Germany, Peter
4
31063
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 Line3 I've tried a couple of methods but nothing seems to be working. Code like
1
15715
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" TextMode="MultiLine"></asp:TextBox> Then I add two lines of text to it: TextBox1.Text = "Line 1\r\nLine 2"; The problem is that a vertical scrollbar is displayed
1
3820
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 want it to be enabled when the user scrolls the vertical scrollbar of a textbox all the way down (indicating that the user at least pretended to read all of the textbox's text). How can I monitor the scrollbar and know when it has reached the end? 2. My multiline textbox has VerticalScrollBar...
2
3433
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 array of strings. I am using a multiline textbox to enter new, edit existing, and view the names in the array. This all works well, but now I want to be able to select one more names from the list displayed in the multiline textbox then click a button to copy the selected names into another list so...
7
15489
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 multiline textbox. Basically, I have created an array of strings which I want to "paste" into a multiline textbox. Any ideas? -- Anil Gupte www.keeninc.net www.icinema.com
4
3821
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 to the next line? Thanks, Gidi.
2
5830
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 in the TextBox. The only way I know of to place things on separate lines in a TextBox without doing it programmatically is the following: <asp:TextBox ID="txtMultiLine" runat="server" TextMode="MultiLine"> Line 1 Line 2 Line 3 </asp:TextBox>
10
3802
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 through selection of options from combo boxes. I want the selected options to each be in a seperate line, and I don't want the user to be able to edit the textbox without using the combo boxes. Here is my code when a selection is made from the combo box: Me.cAbnormalities.Locked = False...
0
9528
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10456
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10230
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
7548
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6788
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5442
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4118
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3731
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2926
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.