How to post code snippets in the forums...
-
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
-
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
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
-
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
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
-
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
TJoe wrote:
If I use the
tags, then I lose newlines like so:
Just put a space character on the blank line
Something
<space>
likethis
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007 -
TJoe wrote:
If I use the
tags, then I lose newlines like so:
Just put a space character on the blank line
Something
<space>
likethis
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007Good 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
-
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
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
-
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
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