Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

What is the meaning of 'trailing newline is stripped'?

  1. Dec 24, 2015 #1
    This is a term I found in a programming tutorial. Since English is not my first language, and this term is also kind of a computer term, I am not so clear with the meaning. Can someone explain it to me?

    Thanks.
     
  2. jcsd
  3. Dec 24, 2015 #2

    Borg

    User Avatar
    Gold Member

    Newline characters indicate that the file has reached the end of the line and that any program should read the next line. The newline character can differ between systems so it is sometimes necessary to remove them. For example, a newline character created in Notepad on Windows will show up as odd text when viewing it on a Unix-based system. Therefore, it is necessary to strip them in order for the file to be read correctly.
     
  4. Dec 24, 2015 #3

    phinds

    User Avatar
    Gold Member
    2016 Award

    To expand slightly on what Borg said, one of the things that is a result of this fact is that if you have an HTML file on a windows system, each line will be terminated by both a carriage return and a line feed. If you then upload that file to a Unix based server and look at the file size, you will see that it is smaller by a number of bytes corresponding to the number of lines, because all the line feeds have been removed.
     
  5. Dec 24, 2015 #4

    jtbell

    User Avatar

    Staff: Mentor

    For which programming language? Which operation or function was the tutorial discussing? If you tell us the context in which that term was used, we can be more specific in our response.
     
  6. Dec 24, 2015 #5

    jim mcnamara

    User Avatar

    Staff: Mentor

    I think Phinds nailed it - carriage control in text files is dependent on the operating system's native carriage control for text files. For modern applications and languages. and Linux/Windows

    I think jtbell is thinking about stuff like FORTRAN and IBM COBOL carriage control words (bytes) that live at the start of a line of text and are ancient holdovers from data entry via punch cards or paper tape. I know because I'm ancient.... and lived through that nightmare.
     
  7. Dec 24, 2015 #6

    jtbell

    User Avatar

    Staff: Mentor

    Actually, I was thinking of C++ and the 'getline' versus '>>' stream input operations.

    Now that we've guessed three different possible contexts, hopefully the OP will tell us which one it is, or if it's something else!
     
  8. Dec 25, 2015 #7
    I'm sorry because I forgot. I think it was python because I was just doing some fast reading. Anyway, I think I do got the point. Thanks.
     
  9. Dec 25, 2015 #8

    meBigGuy

    User Avatar
    Gold Member

    Between Unix and Windows the carriage return is added/removed, not the newline. In Unix, text lines are terminated with newline only (\n).

    It's impossible to answer the OP with any specificity since we don't know the context. For example, json has rules about newlines.
    Or, maybe the tutorial was an example about how one could strip newlines.
     
  10. Dec 25, 2015 #9

    phinds

    User Avatar
    Gold Member
    2016 Award

    OOPS. Thanks.
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook




Similar Discussions: What is the meaning of 'trailing newline is stripped'?
  1. Newline in fortran (Replies: 1)

Loading...