Web Analytics Made Easy -
StatCounter Line breaks from Access DB - CodingForum

Announcement

Collapse
No announcement yet.

Line breaks from Access DB

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Line breaks from Access DB

    Hi there,

    I am a total newbie with ASP so this might be simple.

    I am using an access db and when I use Response.Write to write certain field to the screen I loose all the paragraph formating that was present in the db.

    So, can anyone tell me how i can replace a line break in the db with a <BR>??

    thanks for any help

    Matt

  • #2
    You can do that but there's another way without replacing the linebreaks.

    <pre>
    <%=rs("fieldname")%>
    </pre>

    The default font for <pre> tags is Courier New. If you want to change the font, just apply css style on it

    <pre style="font:normal 12px Verdana">

    </pre>
    Glenn
    vBulletin Mods That Rock!

    Comment


    • #3
      That's all well and good but in case mattym wants the alternative, all you need to do is:
      Code:
      FormattedText = Replace(TextFromDB, vbNewLine, "<br />")
      This cropped up in a thread somewhere here @ CF (or perhaps @ SPF), but I can't find it now...
      Marcus Tucker / www / blog
      Web Analyst Programmer / Voted SPF "ASP Guru"

      Comment


      • #4
        I have that in a function...

        Code:
        Function VbCrLfToBreak(ByVal str)
        	If IsNull(str) Then Exit Function
        	VbCrLfToBreak = Replace(str,vbCrLf,"<br />")
        End Function
        Then all you would need to do is paste the function name around your db variable:

        Code:
        MyDBVar = VbCrLfToBreak(MyDBVar)
        Response.Write(MyDBVar)
        ... or even shorter:

        Code:
        Response.Write(VbCrLfToBreak(Server.HTMLEncode(MyDBVar)))
        ... note the Server.HTMLEncode() function, it's designed for HTML.
        Last edited by whammy; Feb 18, 2004, 11:04 PM.
        Former ASP Forum Moderator - I'm back!

        If you can teach yourself how to learn, you can learn anything. ;)

        Comment


        • #5
          Originally posted by [email protected]
          That's all well and good but in case mattym wants the alternative, all you need to do is:
          Code:
          FormattedText = Replace(TextFromDB, vbNewLine, "<br />")
          This cropped up in a thread somewhere here @ CF (or perhaps @ SPF), but I can't find it now...
          I know that solution too and have seen it here in CF but, IMO, using the <pre> tag is the best solution because you don't need additional processing on the server like replacing all linebreaks with <br />s.
          Glenn
          vBulletin Mods That Rock!

          Comment


          • #6
            http://www.codingforum.net/showthrea...threadid=31221 might be the relevant link.

            Alex
            yourmusicforums.com

            Comment


            • #7
              Whammy, that's quite funny! Usually I'm the one modularizing everything... but I just didn't this time! Touché, monsieur!! (You got me!) lol

              Jeskel, It's not the one I was thinking of, but it *is* relevant!
              Last edited by [email protected]; Feb 19, 2004, 04:03 AM.
              Marcus Tucker / www / blog
              Web Analyst Programmer / Voted SPF "ASP Guru"

              Comment


              • #8
                Originally posted by [email protected]

                Jeskel, It's not the one I was thinking of, but it *is* relevant!
                Maybe this?
                Glenn
                vBulletin Mods That Rock!

                Comment


                • #9
                  glenn: at least that's the one in which I learned the tricks
                  Alex
                  yourmusicforums.com

                  Comment


                  • #10
                    Originally posted by glenngv
                    Maybe this?
                    Nope! That's not the one! lol

                    (It probably *was* @ SPF....)
                    Marcus Tucker / www / blog
                    Web Analyst Programmer / Voted SPF "ASP Guru"

                    Comment

                    Working...
                    X