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.
Check out Environment.NewLine
. As for web pages, break lines with <br /> or <parata /> tags.
You need to use HTML on a web page to get line breaks. For example "<br/>" will give you a line break.
it's : vbnewline for example Msgbox ("Fst line" & vbnewline & "second line")
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.
If you are using something like this.
Response.Write("Hello \r\n")
Response.Write("World \r\n")
and the output is
Hello\r\nWorld\r\n
Then you are basically looking for something like this
Response.Write("Hello <br/>")
Response.Write("World <br/>")
This will output
Hello
World
you can also just define "<br />" as constant and reuse it
eg.
Public Const HtmlNewLine as string ="<br />"
Response.Write("Hello " & HtmlNewLine)
Response.Write("World " & HtmlNewLine)
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"
in Vb.net 2005 I tried controlchars.crlf, controlchars.cr, controlchars.lf, vbcrlf, vblf but I am not able to print a new line character. the code is
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click Dim x, y As Integer
For x = 1 To 8
For y = 1 To x
Label1.Text = Label1.Text + Str(y) + " "
Next y
Label1.Text = Label1.Text + Environment.NewLine
Next x
End Sub
------------- Output I want 1 12 123 1234 12345 123456 1234567 12345678 ----------------- what I did I have used a wide Label and a button the code inside the button is given above.
any suggestion may kindly be forwarded to [email protected]
(Er. S.Saurav, M.Tech(IT))