replacing carriage returns?

Discussion in 'ASP General' started by Jerome, Jan 31, 2005.

  1. Jerome

    Jerome Guest

    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
     
    Jerome, Jan 31, 2005
    #1
    1. Advertisements

  2. Jerome

    larrybud2002 Guest

    don't use Chr(13), use

    vbcrLF
     
    larrybud2002, Jan 31, 2005
    #2
    1. Advertisements

  3. Jerome

    McKirahan Guest

    <% 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.
     
    McKirahan, Jan 31, 2005
    #3
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.