textbox text property

  • Thread starter Thread starter Bill Rowell
  • Start date Start date
B

Bill Rowell

This question is driving me nuts because I'm sure its easy to do...

If I have a text box control and a user enters some text with new line
characters in it, how could I turn around and parse that in VB?

I've tried using "\n", "\r\n", etc. and nothing seems to work. Now, I've
been trying to detect it using IndexOf, perhaps thats my problem?

Thanks!
 
* "Bill Rowell said:
This question is driving me nuts because I'm sure its easy to do...

If I have a text box control and a user enters some text with new line
characters in it, how could I turn around and parse that in VB?

I've tried using "\n", "\r\n", etc. and nothing seems to work. Now, I've
been trying to detect it using IndexOf, perhaps thats my problem?

Use 'ControlChars.NewLine', 'Environment.NewLine', or 'vbNewLine':

\\\
Me.Label1.Text = _
"Hello" & ControlChars.NewLine & _
"World"
///

Notice that this won't reduce performance, because the compiler detects
that the whole text on the right side of the assignment is a single
constant and stores it as one constant in the binary image. At runtime,
no concatenations are performed.
 
I've tried Environment.Newline and ControlChars.NewLine and neither of those
worked.

I'll try vbnewline.

-Bill
 
Bill,

You can use the Split function instead of the split method on the string
object which accepts a string delimiter and the code is a little simpler:

<code (VB.NET) >
Dim astr() As String = Split(Me.TextBox1.Text, Environment.NewLine)
Dim s As String
For Each s In astr
Console.WriteLine(s + "+(CrLf)")
Nex
</code>


-Sam Matzen
 
Back
Top