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

  • Thread starter Thread starter hilman
  • Start date Start date
  • Tags Tags
    English
Join the discussion
Registration is free. Start your own thread to ask a follow-up.
8 replies · 2K views
hilman
Messages
17
Reaction score
0
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.
 
Physics news on Phys.org
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.
 
  • Like
Likes   Reactions: hilman
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.
 
  • Like
Likes   Reactions: jim mcnamara
hilman said:
This is a term I found in a programming tutorial.

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.
 
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.
 
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!
 
  • Like
Likes   Reactions: jim mcnamara
jtbell said:
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.
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.
 
phinds said:
because all the line feeds have been removed.

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.
 
  • Like
Likes   Reactions: phinds
meBigGuy said:
Between Unix and Windows the carriage return is added/removed, not the newline. In Unix, text lines are terminated with newline only (\n).
OOPS. Thanks.