473,394 Members | 1,726 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Read TextBox line by line

Hello,

I have a text box that I am entering items into line by line. I want to read in the data one line at a time into a variable through a loop. I know the textbox does not have a readline attribute, but is there any way I can read a textbox line by line, or should I be using a different control to do so? I'm using VB.Net. Thanks.

Sean Merron
May 17 '07 #1
7 23816
TRScheel
638 Expert 512MB
Hello,

I have a text box that I am entering items into line by line. I want to read in the data one line at a time into a variable through a loop. I know the textbox does not have a readline attribute, but is there any way I can read a textbox line by line, or should I be using a different control to do so? I'm using VB.Net. Thanks.

Sean Merron

I would assume it to have a Environment.NewLine at the end of each line, so you could split by that. I will come back to this thread in like 30 minutes when I get some time to look it up exactly for you.
May 17 '07 #2
TRScheel
638 Expert 512MB
I would assume it to have a Environment.NewLine at the end of each line, so you could split by that. I will come back to this thread in like 30 minutes when I get some time to look it up exactly for you.

Ya, doing this:

Expand|Select|Wrap|Line Numbers
  1. MyMultiLineTextBox.Text.Split(Environment.NewLine)
will return an array of strings, one for each line.
May 17 '07 #3
Thanks I'll give it a whirl!
May 17 '07 #4
Only problem I'm having is that it's keeping the carriage returns within the string. Any way to get rid of those?
May 17 '07 #5
Plater
7,872 Expert 4TB
Use .Trim() on each line?
Expand|Select|Wrap|Line Numbers
  1. string[] mylines = mytextbox.Split(Environment.Newline);
  2. for(int i=0;i<mylines.Length;i++)
  3. {
  4.    string currentstring=mylines[i].Trim();
  5. }
  6.  
May 17 '07 #6
Fore some reason the trim isn't removing the carriage return. The first variable in teh array doesn't ahve it, but all other variables have a carraige return before them.

Expand|Select|Wrap|Line Numbers
  1.                     Dim strComputer, arrComputers() As String
  2. arrComputers = txtEndpoints.Text.Split(Environment.NewLine)
  3. Dim i As Integer = 0
  4. For i = LBound(arrComputers) To UBound(arrComputers)
  5.      strComputer = Trim(arrComputers(i))
  6.      Call MsgBox(strComputer)
  7. Next
May 17 '07 #7
Plater
7,872 Expert 4TB
Ah ha!
There is probably both a \n and a \r and your environment.newline is only removing \r.
Investigate Trim() and Split() and find out where to handle that.
OR
Expand|Select|Wrap|Line Numbers
  1. string mytext=mytextbox.text;
  2. mtext.Replace("\r","");
  3.  
then do a .Split("\n"); and see where it gets you?
May 17 '07 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Jonas | last post by:
I want the user to be able to write like http://www.google.com in one textBox and Google in an other textBox. Than I want the user to press a button when done. The text will then be past like...
8
by: Fred | last post by:
Hello, Is there a way to read values from the registry as regular instead of verbatim? Regards, Fred
0
by: Jerry | last post by:
Below is ALL the code for all the databases... Here's the problem: I callup the aspx file in IE and the form comes up just fine. When I select a person to update, I get the subject error. ...
7
by: I am Sam | last post by:
I have a DataGrid that is passing information to a stored procedure properly but the parameters aren't being casted properly. I was woundering if anyone can tell me how I should properly cast the...
3
by: Brad Rogers | last post by:
All, Being immersed in vb.net and trying CSharp after almost a year I forgot the differences. I like vb fixing the uppercase/lowercase names and seeming to be more flexible to code entry. ...
14
by: MLH | last post by:
I use A97. I've gotten used to reading values from textbox controls on forms, I've come to rely on it pretty heavily. My habit spills over into reports. I'm uncertain whether I can reliably read...
3
by: Ray | last post by:
Hello World, I made a Windowsform that reads data from a CSV file. It works fine, but when I have read the data of a record I have to re-Debug the form to read another record. So when I put a...
7
by: Problematic coder | last post by:
Dim objdr As Data.OracleClient.OracleDataReader = Nothing Dim objcnn As Data.OracleClient.OracleConnection = Nothing Dim objcom As Data.OracleClient.OracleCommand objcom = New...
1
by: KokilaB | last post by:
Hi, I having a column named Steps which has more than five steps in it with line break now i want to read it line by line. Example: Steps has the following data in one field. 1.Type the...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
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,...
0
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.