Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

New line character in VB.Net?

Tags:

string

vb.net

I am trying to print a message on a web page in vb.net. I am trying to get the messages in new lines. I tried using the "\r\n" and the new line character. But this is getting printed in the page instead of it comming to the next line. Please let me know if there is any alternative.

like image 397
Vinod Avatar asked Feb 05 '09 12:02

Vinod


People also ask

What is VB new line?

vbNewLine inserts a newline character that enters a new line. In the below line of code, you have two strings combined by using it. Range("A1") = "Line1" & vbNewLine & "Line2" When you run this macro, it returns the string in two lines.

How do you break a line in Visual Basic?

Use the line-continuation character, which is an underscore ( _ ), at the point at which you want the line to break. The underscore must be immediately preceded by a space and immediately followed by a line terminator (carriage return) or (starting with version 16.0) a comment followed by a carriage return.

How do I add a new line in Visual Studio?

Today I learned How to find and replace with a newline in Visual Studio Code. In the local searchbox ( Ctrl + F ) you can insert newlines by pressing Ctrl + Enter . If you use the global search ( Ctrl + Shift + F ) you can insert newlines by pressing Shift + Enter .


4 Answers

Check out Environment.NewLine. As for web pages, break lines with <br> or <p></p> tags.

like image 169
Anton Gogolev Avatar answered Oct 16 '22 23:10

Anton Gogolev


Environment.NewLine is the most ".NET" way of getting the character, it will also emit a carriage return and line feed on Windows and just a carriage return in Unix if this is a concern for you.

However, you can also use the VB6 style vbCrLf or vbCr, giving a carriage return and line feed or just a carriage return respectively.

like image 38
Garry Shutler Avatar answered Oct 17 '22 01:10

Garry Shutler


The proper way to do this in VB is to use on of the VB constants for newlines. The main three are

  • vbCrLf = "\r\n"
  • vbCr = "\r"
  • vbLf = "\n"

VB by default doesn't allow for any character escape codes in strings which is different than languages like C# and C++ which do. One of the reasons for doing this is ease of use when dealing with file paths.

  • C++ file path string: "c:\\foo\\bar.txt"
  • VB file path string: "c:\foo\bar.txt"
  • C# file path string: C++ way or @"c:\foo\bar.txt"
like image 17
JaredPar Avatar answered Oct 16 '22 23:10

JaredPar


You need to use HTML on a web page to get line breaks. For example "<br/>" will give you a line break.

like image 14
andynormancx Avatar answered Oct 17 '22 00:10

andynormancx