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. Advertising

  2. Jerome

    Guest

    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
     
    , Jan 31, 2005
    #2
    1. Advertising

  3. Jerome

    McKirahan Guest

    "Jerome" <> wrote in message
    news:...
    > 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.
     
    McKirahan, Jan 31, 2005
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Iceberg

    Carriage Returns and sockets

    Iceberg, Sep 6, 2003, in forum: Perl
    Replies:
    1
    Views:
    1,185
    Iceberg
    Sep 6, 2003
  2. Schroeder
    Replies:
    1
    Views:
    583
    Jim Gibson
    Jan 26, 2005
  3. Mario Vargas

    Replacing Carriage Returns in VB.NET

    Mario Vargas, Oct 21, 2003, in forum: ASP .Net
    Replies:
    3
    Views:
    14,698
    Dragos Marian Barbu
    Nov 10, 2003
  4. Brian
    Replies:
    1
    Views:
    317
    Craig Deelsnyder
    Jun 17, 2004
  5. Steve Anderson
    Replies:
    3
    Views:
    277
    Steve Anderson
    Jun 21, 2004
Loading...

Share This Page