Meta Stack Exchange is where users like you discuss bugs, features, and support issues that affect the software powering all 158 Stack Exchange communities.

What is meta?
Here's how it works:
  1. Any Stack Exchange user can ask a question
  2. The community provides support, votes on ideas, and reports bugs
  3. Your voice helps shape the way Stack Exchange operates

Possible Duplicate:
How about newlines within comments?

When posting a comment in stackoverflow how do I add newlines? I pasted some multi-line code example and stackoverflow stipped the newline characters and the code looks ugly!

share|improve this question

migrated from Aug 13 '12 at 13:23

This question came from our site for professional and enthusiast programmers.

marked as duplicate by Al E., Shadow Wizard, Brad Mace, Adam Lear Aug 13 '12 at 14:14

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

if (args.Length > 0) { bool connected = bool.Parse(args[0]); string connectedString = connected ? "Connected" : "Not Connected"; } – Tacky Tacky Aug 13 '12 at 13:17
Look how ugly that paste is! Is there a way to paste code which remains formatted? – Tacky Tacky Aug 13 '12 at 13:18
Code should not be posted in comments. Add it to the question itself, or if commenting on answer have its author add it to the post itself where is can be formatted properly. – Shadow Wizard Aug 13 '12 at 14:11

From How do comments work?:

Comments are intentionally short, having maximum length of 600 characters, and allow only limited markup.

As such, they intentionally do not support newlines either.

You can use the help link next to a comment box to see what is supported; from the comment formatting help:

Comments support only bold, italic, code and links; in addition, a few shorthand links are available.

share|improve this answer

This is a question for Meta/FAQ, but you can use ` to delimit a code-portion in comments.

This is an

share|improve this answer
If you hit help beside the comment box, it gives you an example of markdown. – David B Aug 13 '12 at 13:22
if (args.Length > 0) { bool connected = bool.Parse(args[0]); string connectedString = connected ? "Connected" : "Not Connected"; } – Tacky Tacky Aug 13 '12 at 13:22
i put the "`" char in front of my code (see above) and it still strips the newlines. – Tacky Tacky Aug 13 '12 at 13:23

Why do you want to put formatted code in a comment? Even with carriage returns I would find that ridiculously hard to read. Put it in the question or answer, then it has full formatting and it will most likely be syntax highlighted in the correct language, making it ever easier to read. Comments are for comments, not for code!

share|improve this answer
What you're saying is true, but sometimes I suggest code that really isn't an answer, but it is definitely a comment. I do this to suggest significant improvements to the code that won't necessarily solve the problem. See here. – gobernador Aug 13 '12 at 14:03
See I would rather have that edited into my answer, then I can make a more constructive decision about what to do with it. Or describe the concept to me and I can edit it (some folks are very "Get off my lawn!" about editing their posts, even when the edit is completely valid). Code samples, even when formatted as code, are absolutely unreadable to me in a comment. – Aaron Bertrand Aug 13 '12 at 14:12
If it's an answer, I agree with you, but I'm of the opinion that one should think twice before editing the code in a question. Additionally, by posting it in comments rather than editing, I can carry on a discussion about it with the OP and ensure he understands why I suggest it. – gobernador Aug 13 '12 at 14:16
@gobernador there is nothing wrong with adding a code sample to a question, rather than changing what's there. And there is also nothing wrong with asking in a comment if you can do so, and conversing about it afterward. Unless it's really a one-liner, I will never appreciate code in a comment. Even with laser-corrected vision. It's terribly annoying. – Aaron Bertrand Aug 13 '12 at 14:18

Not the answer you're looking for? Browse other questions tagged .