469,281 Members | 2,486 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

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

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 23576
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

Post your reply

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

Similar topics

1 post views Thread by Jonas | last post: by
7 posts views Thread by I am Sam | last post: by
3 posts views Thread by Brad Rogers | last post: by
7 posts views Thread by Problematic coder | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.