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

  • Thread starter Thread starter hilman
  • Start date Start date
  • Tags Tags
    English
Click For Summary

Discussion Overview

The discussion revolves around the term "trailing newline is stripped," as encountered in a programming tutorial. Participants explore its meaning, particularly in the context of different operating systems and programming languages, including Python, C++, and historical languages like FORTRAN and COBOL.

Discussion Character

  • Exploratory
  • Technical explanation
  • Debate/contested

Main Points Raised

  • One participant seeks clarification on the term due to language barriers and asks for an explanation.
  • Another participant explains that newline characters indicate the end of a line and may need to be stripped for proper file reading across different systems.
  • A further contribution notes that HTML files on Windows include both carriage return and line feed, leading to discrepancies in file size when viewed on Unix systems.
  • Several participants inquire about the specific programming language and context of the tutorial to provide a more tailored explanation.
  • One participant mentions the historical context of carriage control in older programming languages, contrasting it with modern applications.
  • Another participant suggests that the discussion may relate to C++ input operations, specifically 'getline' versus '>>' stream operations.
  • A later reply emphasizes the need for context, mentioning that JSON has specific rules regarding newlines.
  • There is a correction regarding the understanding of carriage return and newline differences between Unix and Windows systems.

Areas of Agreement / Disagreement

Participants express varying interpretations of the term and its implications across different programming contexts. There is no consensus on a single definition or application, as multiple views and contexts are presented.

Contextual Notes

The discussion highlights the dependence on specific programming languages and contexts, which are not fully resolved. There are also references to historical practices in programming that may not apply to modern languages.

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.
 
Technology 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.
 

Similar threads

  • · Replies 9 ·
Replies
9
Views
5K
Replies
69
Views
11K
  • · Replies 16 ·
Replies
16
Views
3K
Replies
16
Views
3K
Replies
37
Views
6K
  • · Replies 8 ·
Replies
8
Views
5K
  • · Replies 112 ·
4
Replies
112
Views
9K
  • · Replies 43 ·
2
Replies
43
Views
8K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 29 ·
Replies
29
Views
4K