DOS/Windows newline is two (2) bytes, 0x0D0A.
UNIX/Linux newline is one (1) byte, 0x0A.
Mac newline is one (1) byte, 0x0D.
How can I write code to find the length of a newline on each platform? Output on Windows will produce two (2) bytes, but output on Linux will produce one (1) byte. I did not find anything related to this in
about_Special_Characters
.
On Windows:
PS C:\src\t> type .\nl.ps1
'`n'.Length
"`n".Length
Both Windows and Linux return the same result.
PS C:\src\t> .\nl.ps1
–
–
–
–
.NET Standard has an API for that, and is a always available from Powershell:
[system.environment]::newline.length
On Windows
PS> [system.environment]::newline.length
On Ubuntu
PS> [system.environment]::newline.length
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
site design / logo © 2019 Stack Exchange Inc; user contributions licensed under cc by-sa 4.0
with attribution required.
rev 2019.9.26.35031