replacing carriage returns?

J

Jerome

Hi, I know this is an old question but I don't find the solution on the
'net ...

The user enters his data into a multiline textarea field.
The data is saved in a TEXT field in a database on a SQL Server.
I want to display that data now, but the carriage returns should be
replaced with <br>! Otherwise the text doesn't have paragraphs.

How do I do that?

This hasn't worked:
<% response.write replace(rsRappAct.Fields.Item("texte").Value, Chr(13),
"<BR>")%>

Thanks a lot!

Jerome
 
L

larrybud2002

Jerome said:
Hi, I know this is an old question but I don't find the solution on the
'net ...

The user enters his data into a multiline textarea field.
The data is saved in a TEXT field in a database on a SQL Server.
I want to display that data now, but the carriage returns should be
replaced with <br>! Otherwise the text doesn't have paragraphs.

How do I do that?

This hasn't worked:
<% response.write replace(rsRappAct.Fields.Item("texte").Value, Chr(13),
"<BR>")%>

don't use Chr(13), use

vbcrLF
 
M

McKirahan

Jerome said:
Hi, I know this is an old question but I don't find the solution on the
'net ...

The user enters his data into a multiline textarea field.
The data is saved in a TEXT field in a database on a SQL Server.
I want to display that data now, but the carriage returns should be
replaced with <br>! Otherwise the text doesn't have paragraphs.

How do I do that?

This hasn't worked:
<% response.write replace(rsRappAct.Fields.Item("texte").Value, Chr(13),
"<BR>")%>

Thanks a lot!

Jerome

<% Response.Write Replace(rsRappAct("texte"),vbCrLf,"<br>")%>


Somewhat off-topic but may be of interest ....

Here's an example of a client-side textarea cleanup I use.

It removes all leading and trailing CrLf's and spaces.

It also converts 3 or more CrLf's to just two.

<html>
<head>
<title>CrLf_Fix.htm</title>
<script type="text/javascript">
function CrLf() {
var rex1 = /^[\r\n\s*]+|[\r\n\s*]+$/g; // trim CrLf's
var rex2 = /(\r\n\s*){2,}/g; // 2max CrLf's
var data = document.forms[0].data.value;
if (data != "") {
var what;
//* remove leading and trailing CrLf's from "textarea":
what = data.replace(rex1,"");
//* replace 3+ consecutive CrLf's with 2 in "textarea":
what = what.replace(rex2,"\r\n\r\n");
if (what != data) document.forms[0].data.value = what;
}
}
</script>
</head>
<body>
<form>
<textarea name="data" cols="52" rows="20"></textarea>
<br>
<input type="button" value="Remove leading, trailing, and multiple CrLf's"
onclick="CrLf()">
<input type="reset" value="Clear">
</form>
</body>
</html>

It's not perfect (suggestions are welcome) but it helps reduce garbage
input.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top