PDA

View Full Version : A question with asp...



MattW
September 17th, 2001, 21:09
I was just wondering if anyone could help me out. I'm using asp for a script that processes a form that has a text box. In the text box, if someone hits enter, I want that to turn up as a <BR>. I've seen somewhere that you can just switch the \n with a <BR>. I know there are commands for it in php and perl, but is there on in asp? Any help would be appreciated! Thanks!

ashben
September 19th, 2001, 05:57
You may try ..

parsedVar = replace(requestedVar,chr(13),"<br>")

.. where requestedVar is the original string variable. BTW, 13 is the ASCII code for Carriage Return.

If you just need to display the contents of the string variable then you may use ..

<%=Server.HTMLEncode(requestedVar)%>

.. this would automatically take care of all character-based encoding.

Beans
September 19th, 2001, 09:37
I believe that chr(13) is the carriage return too. But I think chr(10) is also required, chr(10) is the linefeed.

meaning, instead of:
parsedVar = replace(requestedVar,chr(13),"<br>")

use:
parsedVar = replace(requestedVar,chr(13)+chr(10),"<br>")

Cyber
September 19th, 2001, 11:31
Originally posted by Beans
I believe that chr(13) is the carriage return too. But I think chr(10) is also required, chr(10) is the linefeed.

meaning, instead of:
parsedVar = replace(requestedVar,chr(13),"<br>")

use:
parsedVar = replace(requestedVar,chr(13)+chr(10),"<br>")

beans, thats correct, but you might also wanna try this:

parsedVar = replace(requestedVar,chr(13)&chr(10),"<br>")

or

CrLf = chr(13)+chr(10)
parsedVar = replace(requestedVar,CrLf,"<br>")

jm4n
September 19th, 2001, 13:13
I believe that chr(13) is the carriage return too. But I think chr(10) is also required, chr(10) is the linefeed.
True, assuming the end user is using Windows. MS Windows/DOS uses CR+LF to terminate a line. Unix and Unix-like systems use only an LF, and Mac systems use only a CR. The browser will send whatever the user's platform uses to terminate lines.

I don't use ASP, but have used VB in the past, and it looks to be similar. So try this instead:

parsedVar = replace(requestedVar,chr(13)&chr(10),"<br>")
parsedVar = replace(requestedVar,chr(10),"<br>")
parsedVar = replace(requestedVar,chr(13),"<br>")

This will replace CR+LF, then any remaining LF, then any CRs, and should handle Unix, Mac, and DOS/Windows browsers.

Of course if ASP has regular expressions (which any Unix language has ;)), you could easily do this in one line...

<EDIT>
In VB, you have constants already declared:

vbCRLF
vbLF
vbCR

Are these not carried over to ASP?
</EDIT>

MattW
September 19th, 2001, 18:34
Thanks for all your help guys, I'm going to try this a little later when I get a chance!