Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Other Discussions
  3. IT & Infrastructure
  4. How to post code snippets in the forums...

How to post code snippets in the forums...

Scheduled Pinned Locked Moved IT & Infrastructure
phpcomtutorialquestion
7 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    TJoe
    wrote on last edited by
    #1

    Can someone tell me the best way to post code snippets to these forums? If I use the <pre> tags, then I lose newlines like so:

    Int32 i = 0;

    // There should be a newline above this line
    Int32 j = 0;

    If I use the <code> tags, then I lose leading whitespace like so: Int32 i = 0; if (0 == i) i = 1; // There should be four spaces before this line.

    Thanks, Tom ----------------------------------------------- Check out my blog at http://tjoe.wordpress.com

    L D 2 Replies Last reply
    0
    • T TJoe

      Can someone tell me the best way to post code snippets to these forums? If I use the <pre> tags, then I lose newlines like so:

      Int32 i = 0;

      // There should be a newline above this line
      Int32 j = 0;

      If I use the <code> tags, then I lose leading whitespace like so: Int32 i = 0; if (0 == i) i = 1; // There should be four spaces before this line.

      Thanks, Tom ----------------------------------------------- Check out my blog at http://tjoe.wordpress.com

      L Offline
      L Offline
      Luc Pattyn
      wrote on last edited by
      #2

      Hi, the PRE tag is the right one for multi-line code snippets the CODE tag is the right one for single-line code snippets the formatting you may loose when using Internet Explorer can be restored using the CodeRescue utility, see one of my articles. :)

      Luc Pattyn [Forum Guidelines] [My Articles]


      this weeks tips: - make Visual display line numbers: Tools/Options/TextEditor/... - show exceptions with ToString() to see all information - before you ask a question here, search CodeProject, then Google


      T 1 Reply Last reply
      0
      • L Luc Pattyn

        Hi, the PRE tag is the right one for multi-line code snippets the CODE tag is the right one for single-line code snippets the formatting you may loose when using Internet Explorer can be restored using the CodeRescue utility, see one of my articles. :)

        Luc Pattyn [Forum Guidelines] [My Articles]


        this weeks tips: - make Visual display line numbers: Tools/Options/TextEditor/... - show exceptions with ToString() to see all information - before you ask a question here, search CodeProject, then Google


        T Offline
        T Offline
        TJoe
        wrote on last edited by
        #3

        Hi Luc, I'm not concerned about copying from the forums to VS. The actual display in the forums is the problem. Newlines are removed when using the PRE tags and leading whitespace is removed when using CODE tags (see my original question). UPDATE: It appears that newlines are not lost when viewing from Firefox (I'm using IE7).

        Thanks, Tom ----------------------------------------------- Check out my blog at http://tjoe.wordpress.com

        L 1 Reply Last reply
        0
        • T TJoe

          Can someone tell me the best way to post code snippets to these forums? If I use the <pre> tags, then I lose newlines like so:

          Int32 i = 0;

          // There should be a newline above this line
          Int32 j = 0;

          If I use the <code> tags, then I lose leading whitespace like so: Int32 i = 0; if (0 == i) i = 1; // There should be four spaces before this line.

          Thanks, Tom ----------------------------------------------- Check out my blog at http://tjoe.wordpress.com

          D Offline
          D Offline
          Dave Kreskowiak
          wrote on last edited by
          #4

          TJoe wrote:

          If I use the

          tags, then I lose newlines like so:

          Just put a space character on the blank line

          Something
          <space>
          like

          this

          A guide to posting questions on CodeProject[^]
          Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
               2006, 2007

          T 1 Reply Last reply
          0
          • D Dave Kreskowiak

            TJoe wrote:

            If I use the

            tags, then I lose newlines like so:

            Just put a space character on the blank line

            Something
            <space>
            like

            this

            A guide to posting questions on CodeProject[^]
            Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
                 2006, 2007

            T Offline
            T Offline
            TJoe
            wrote on last edited by
            #5

            Good idea. It appears that newlines are not lost when viewing from Firefox (I'm using IE7).

            Thanks, Tom ----------------------------------------------- Check out my blog at http://tjoe.wordpress.com

            1 Reply Last reply
            0
            • T TJoe

              Hi Luc, I'm not concerned about copying from the forums to VS. The actual display in the forums is the problem. Newlines are removed when using the PRE tags and leading whitespace is removed when using CODE tags (see my original question). UPDATE: It appears that newlines are not lost when viewing from Firefox (I'm using IE7).

              Thanks, Tom ----------------------------------------------- Check out my blog at http://tjoe.wordpress.com

              L Offline
              L Offline
              Luc Pattyn
              wrote on last edited by
              #6

              Hi Tom, I am unaware of any loss of newlines, with the exception of the empty line (that's why you should at least have a space on every line). I always copy code snippets from Visual Studio to the message form, and I am using IE6 (an earlier test showed no difference in formatting behavior between IE6 and IE7). They typically need two modifications: - adding a space to an empty line; - replacing a < by the & lt; string to avoid HTML interpretation. Are you saying all your code gets turned into a single line? Is your system special in some way: - Do you have a special regional setting? - A different clipboard? :)

              Luc Pattyn [Forum Guidelines] [My Articles]


              this weeks tips: - make Visual display line numbers: Tools/Options/TextEditor/... - show exceptions with ToString() to see all information - before you ask a question here, search CodeProject, then Google


              T 1 Reply Last reply
              0
              • L Luc Pattyn

                Hi Tom, I am unaware of any loss of newlines, with the exception of the empty line (that's why you should at least have a space on every line). I always copy code snippets from Visual Studio to the message form, and I am using IE6 (an earlier test showed no difference in formatting behavior between IE6 and IE7). They typically need two modifications: - adding a space to an empty line; - replacing a < by the & lt; string to avoid HTML interpretation. Are you saying all your code gets turned into a single line? Is your system special in some way: - Do you have a special regional setting? - A different clipboard? :)

                Luc Pattyn [Forum Guidelines] [My Articles]


                this weeks tips: - make Visual display line numbers: Tools/Options/TextEditor/... - show exceptions with ToString() to see all information - before you ask a question here, search CodeProject, then Google


                T Offline
                T Offline
                TJoe
                wrote on last edited by
                #7

                Sorry for the confusion. I meant that empty lines (no spaces or text) are removed. I now know to include a single space to keep the empty line using the PRE tags. In firefox, empty lines work fine. For the CODE tags, if it should only be used for a single line, then obviously the leading whitespace isn't important.

                Thanks for your help, Tom ----------------------------------------------- Check out my blog at http://tjoe.wordpress.com

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups