Read Textbox Line By Line

Joined
Jan 15, 2009
Messages
21
Programming Experience
5-10
I have a multiline textbox from which I would like to read each individual line and store it in an array. I don't want to store each carriage return, I want the line itself.

I have been using this, but it only records lines followed by carriage returns.

Dim arra() = txtReceipt.Text.Split(Environment.NewLine)

Here is a visual example:
http://www.java2s.com/Tutorial/CSharpImages/TextBoxMultiline.PNG

From that top right textbox, I would want arra(0) to be "Type some stuff here (and hit the return and" and arra(1) to be "tab keys...)"

Is there a way to accomplish this?
 
I presume you're talking about taking word wrap into account. If so then I think you'd have to use a For loop to go through every character and call GetLineFromCharIndex. Each time the return value of that method increases you've gone to the next line, which includes "soft" lines breaks.
 
Hack - I had no idea, that's why I came here. I thought there might be something built in to visual studio that could find this for me.

jmc - That sounds perfect. I will have to wait until this afternoon to try it out, so I will let you know my results later. Thanks!
 
Back
Top