Click to See Complete Forum and Search --> : New Line Character


Jim McCreary
March 30th, 2004, 06:54 PM
I am a C++ coder trying to learn Visual Basic .NET

I want to create a multi-line String to put into a TextBox. In VC++ I would just concatinate the lines with "\r\n" between the line.

CString cs = "Line one" + "\r\n" + "Line two"

What is the equivalent in Visual Basic .NET using the String variable type?

Craig Gemmill
March 30th, 2004, 07:23 PM
There are actually several ways to do this (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vblr7/html/vamscmiscellaneousconstants.asp), and the best method is what you end up being most comfortable with. The most common method, however, is to use the vbCrLf constant. Also, in VB you want to use the & operator on String concats, as the + operator performs numeric bounds checking, which causes it to be slower.


'CString cs;
Dim cs as String

'cs = "Line one" + "\r\n" + "Line two";
cs = "Line one" & vbCrLf & "Line two"