The new line numbers inserted when using syntax coloring code tags is causing me problems when copying and pasting code. Here are some examples:

http://www.daniweb.com/techtalkforums/post311344-32.html

I copy and paste the code to my editor. This is how it looks when it's selected in my browser:[IMG]http://img522.imageshack.us/img522/7406/picture1ji6.png[/IMG]
And this is how my code looks when it's in the editor:

1.
#include <stdio.h>
2.
#include <string.h>
3.

4.
int main(void) {
    5.
    6.
    char mystring[] = "this is a test.\n";
    7.
        char *p = strchr(mystring, '\n');
    8.
        if (p != NULL) *p = '\0';
    9.
        printf("%s no newlines should occur.\n", mystring);
    10.
        11.
}

Sometimes, instead of line numbers I get pound symbols (#) instead. I'm using Firefox 2.0.

Recommended Answers

All 22 Replies

I don't have this problem at all. I tried copying/pasting from both Firefox and IE into Windows Notepad. Perhaps it's a problem with your editor?

In the meantime, a workaround would be to click the Reply w/ Quote button and then copy the post contents from the editor window.

Since the majority of the code posted within the forums is just for discussion purposes, I thought the line numbers would be a great aid towards talking about a particular piece of code. ie. "You have an error on line #5"

Perhaps it's a problem with your editor?

Nah, before I was using Xcode, but using TextEdit didn't seem to make a difference. To me, it seems to be somewhat on the browser end of things.

Just tried Safari now - no difference.

I'll let you know how things are on Linux when I next boot onto Debian.

In the meantime, a workaround would be to click the Reply w/ Quote button and then copy the post contents from the editor window.

Thanks; it seems like I'll be needing to do this whenever I need to try out code in my compiler from now on.

I have a mac as well so I am going to see if it works for me.

Perhaps it's a problem with your editor?

Same issue with my editor. DevShed had a similar issue and a better workaround.

[imo]Even though the better solution was to leave it as it was.[/imo]

Dave, are you in Linux?

Nope.

Although it may first seem like a great idea...

Since the majority of the code posted within the forums is just for discussion purposes, I thought the line numbers would be a great aid towards talking about a particular piece of code. ie. "You have an error on line #5"

That actually happens about 0.5% of the time. IMO it's not worthwhile to inconvenience 99.5% of the rest.

0.5% of the time you discuss the code snippets and 99.5% of the time you copy them into your editor and compile them? I suspect that's not the case with the vast majority of traffic to the programming forums.

0.5% of the time you discuss the code snippets and 99.5% of the time you copy them into your editor and compile them? I suspect that's not the case with the vast majority of traffic to the programming forums.

I use colors and other tools available [when available] because that is far more effective than looking at a printout from 1972. So yes, that is the case.

BTW, I found this, FWIW.

Still investigating a solution. In the meantime, I've confirmed the problem is not with the web browser but rather with your editor. When using Firefox 2 and Windows Vista, I was able to copy/paste just fine into Notepad but I got line numbers when copy/pasting into Zend PHP Studio.

FireFox1.5 into VEdit -- line numbers.
FireFox1.5 into Notepad -- line numbers
Firefox1.5 into Wordpad -- line numbers

IE7 into VEdit -- one line, no formatting
IE7 into Notepad -- one line, no formatting
IE7 into Wordpad -- no formatting

Opera9 -- seems to work.

I see no reason for line numbers either. I doubt it's worth the trouble to track down the solution. And it would be too presumptuous to require a specific browser.

It would also be beneficial IMO to put back the label "code" and the lines above and below the code. Don't have to change the code format, just the head and tail.

I went ahead and implemented the same workaround DevShed uses that Dave suggested. Of course it's not that elegant ... but let's see.

I like that change -- now we can turn line numbers on and off as we please. Hope you keep this feature. :)

I second that. It wasn't that the line numbers were bad, but if they interfere with my ease of copying and pasting, then it becomes more a nuisance. This solution is great. :)

I went ahead and implemented this in our code snippet library as well. Here is an example:

http://www.daniweb.com/code/snippet582.html

You'll notice that with the line numbers, when code is too long for the line, it very cleanly wraps around with the line number indicating it's just a wrap around. I think this is a lot nicer than the messy horizontal scrollbars, especially with very long snippets.

I like that change -- now we can turn line numbers on and off as we please. Hope you keep this feature. :)

I think this will work. Can you tell how many line are in the code block? If so, could you please add the toggle to the top of the block also if the block is greater than, say, 30 lines? If not, just add the toggle to the top. Many times people post 2 or more (window) pages of code and if we see something we wish to comment on at the top, we have to scroll all the way down, then all the way back up. This would also delineate the block nicely.

I actually went ahead and decided to allow the code to be as long as it needs to be. I found the scrollbars incredibly annoying. I prefer to read code the same way that I do everyday in my IDE ... by utilizing the full height of my monitor, as opposed to being forced to only see a couple of lines of code at a time. I think it has something to do with me not having a photographic memory.

The new line numbers inserted when using syntax coloring code tags is causing me problems when copying and pasting code.

Click on the link "toggle plain text" which appears below the code snippet and then try copy-pasting. It works out to be fine.

Click on the link "toggle plain text" which appears below the code snippet and then try copy-pasting. It works out to be fine.

You didn't read the entire thread did you? ;)

http://www.daniweb.com/techtalkforums/thread69244-1.html#post311482

Dani implemented this after I complained about it - it's all good now.

I guess this is what I get for jumping at conclusions.

Btw the currently revamped system (toggle between plain text adopted from devshed) is good. Now its the RPG's turn....

I had this problem elsewhere. The problem was the way I grabbed the code from the editor to put it on the website.

The editor had a single code which says "line number goes here" The actual number displayed for the line depended on where it was in the file.

When you copy from the editor screen with the Windows drag-and-copy method, it picks up the line number codes, instead of the actual line numbers. Then when you paste, you get a mess, because it's an unprintable character.

If instead, I exported the portion of text from the editor, then the numbers stayed put.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.