By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,975 Members | 1,236 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,975 IT Pros & Developers. It's quick & easy.

replacing carriage returns?

P: n/a
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
Jul 22 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a

Jerome wrote:
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

Jul 22 '05 #2

P: n/a
"Jerome" <no****@nospam.com> wrote in message
news:OR**************@TK2MSFTNGP09.phx.gbl...
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.
Jul 22 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.