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

  • Thread starter hilman
  • Start date
  • Tags
    English
In summary, the conversation discussed the term "newline character" and its significance in programming. The character indicates the end of a line in a text file and can cause issues when transferring files between different operating systems. The purpose of this conversation was to clarify the meaning of this term for someone whose first language is not English. The context of the term was not specified, but it is possible that it was mentioned in a Python tutorial.
  • #1
hilman
17
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
  • #2
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 hilman
  • #3
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 jim mcnamara
  • #4
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.
 
  • #5
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.
 
  • #6
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 jim mcnamara
  • #7
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.
 
  • #8
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 phinds
  • #9
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.
 

1. What is a trailing newline?

A trailing newline refers to a line break at the end of a sequence of characters in a text file.

2. What does it mean for a trailing newline to be stripped?

When a trailing newline is stripped, it means that the line break at the end of a sequence of characters is removed or deleted from the text file.

3. Why is a trailing newline stripped?

A trailing newline is often stripped in programming languages or text editors to avoid any unintended or unnecessary line breaks in the output.

4. How does stripping a trailing newline affect the text file?

Stripping a trailing newline does not change the content of the text file, but it may affect the way the file is displayed or interpreted by certain programs or systems.

5. Is stripping a trailing newline always necessary?

No, stripping a trailing newline is not always necessary. In some cases, it may be preferred to keep the line break at the end of a sequence of characters for formatting or readability purposes.

Similar threads

  • Programming and Computer Science
2
Replies
69
Views
4K
  • Programming and Computer Science
Replies
16
Views
1K
  • Programming and Computer Science
2
Replies
37
Views
2K
  • Programming and Computer Science
Replies
16
Views
1K
  • Programming and Computer Science
Replies
9
Views
4K
  • Programming and Computer Science
Replies
8
Views
2K
  • Art, Music, History, and Linguistics
4
Replies
112
Views
5K
  • Programming and Computer Science
Replies
4
Views
983
Replies
11
Views
796
  • Programming and Computer Science
Replies
2
Views
1K
Back
Top