views:

12798

answers:

10

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.

+2  A: 

Try Environment.NewLine.

Gerrie Schenck
this won't do anything for a web environment. You need a <br /> tag
Chris Ballance
+6  A: 

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

Anton Gogolev
You mean tags right?
Gerrie Schenck
+3  A: 

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

andynormancx
A: 
VbCr

Try that.

Natrium
VbCr = "\r". vbCrLf = "\r\n" and is much more common
JaredPar
A: 

it's : vbnewline for example Msgbox ("Fst line" & vbnewline & "second line")

Omar Abid
+2  A: 

Your need to use the html/xhtml break character:

<br />
Chris Pebble
+2  A: 

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.

Garry Shutler
Why the downvote?
Garry Shutler
I suspect because while your answer addresses how to get the newline character that isn't actually the answer the questioner needs. What he actually needs is an HTML break. As has been covered by other answers.None of the answers that just talk about NewLine are really answering the question.
andynormancx
Although, that said, the question is incredibly unclear. I guess "print a message on a web page" _could_ actually mean he is trying to use alert() or msgbox() on the web page, which would make it a whole different question.
andynormancx
Yeah, the question is poor if that is what he wants as he mentions "\r\n" which is C style for vbCrLf, I assumed that was the answer he was looking for.
Garry Shutler
+4  A: 

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)
Sachin
If you want to go all out, you could even subclass Environment and add the HtmlNewLine to it...
John Baughman
:) yes John. Also we can add as Extension methods if need be.
Sachin
A: 

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"
JaredPar
-1 for ... This is a completely valid and correct answer
JaredPar
These methods are depricated in .NET and the standard Environment.NewLine should be used. And since the OP was looking at ASP.NET, these constants wouldn't work anyway. HTML <BR/> tags are the correct way to provide the solution sought.
John Baughman
I was referring to the VB6 style constants. Just so we are clear. I still wouldn't have voted this down though.
John Baughman
@John, actually you are wrong. The vb constants are in no way deprecated.
JaredPar
A: 

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))

suman saurav