ASP Line-breaks - \n?
Asked Answered
T

6

15

I have been searching for a way to insert linebreaks in my code for when I view my source. I am not looking for <br />

Something like the PHP equiv to \n

Any ideas on how to do this in ASP? I will be placing this inside a string.

Thomasina answered 14/12, 2008 at 20:48 Comment(0)
L
26

There's no way to do it inside a string. You will have to append vbCrLf like so:

Response.Write "hello" & vbCrLf & "world"

If you want to include it in the string, you could do a replace after like so:

output = "hello\nworld"
output = Replace(output, "\n", vbCrLf)
Response.Write output
Liberia answered 14/12, 2008 at 20:57 Comment(1)
On a side note, in ASP.NET you'll want to use Environment.NewLine instead.Phil
H
2

In addition to the \n method, I have also embedded the HTML tag <BR> and used:

Response.Write "First Line Of Text<br>Second Line Of Text<br>Third line Of Text"
Hippie answered 14/12, 2008 at 21:42 Comment(0)
A
1

For me, using "\n" didn't work and resulted in \n appearing as text on the webpage rather than as a newline in the source code view, however using chr(10) did work. Using CrLf was not an option for me as that generates a windows line ending (\r\n) and I needed the Linux line ending which is just the linefeed (\n).

Avruch answered 15/7, 2015 at 10:37 Comment(0)
G
0

easiest way is just print html break line with response function

like this : Response.Write "<BR>" you can send any other HTML command as well with this method just watch for Quotation marks

Gareth answered 2/3, 2017 at 19:20 Comment(0)
B
0

The best way is using <br/> tag like:

<%@ Language="VBScript" %>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8" />
    <title></title>

 </head>
<body>
      <%
       dim i
       for i=0 to 10
       response.write(i & "<br/>")
       next 
       %>
</body>

Barvick answered 31/8, 2018 at 6:15 Comment(0)
B
0

You can use the defined const vbCrLf, vbCr and vbLf

vbCrLf = char(13) & char(10) 'Same as PHP \r\n
vbCr   = char(13)            'Same as PHP \r
vbLf   = char(10)            'Same as PHP \n
Basipetal answered 17/7, 2022 at 17:30 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.