DOS/Windows 换行符是两 (2) 个字节,0x0D0A。UNIX/Linux 换行符是一 (1) 个字节,0x0A。Mac 换行符是一 (1) 个字节,0x0D。
如何编写代码来查找每个平台上换行符的长度?Windows 上的输出将产生两 (2) 个字节,但 Linux 上的输出将产生一 (1) 个字节。我在 中没有找到与此相关的任何内容about_Special_Characters
。
在 Windows 上:
PS C:\src\t> type .\nl.ps1
'`n'
'`n'.Length
"`n"
"`n".Length
Windows 和 Linux 都返回相同的结果。
PS C:\src\t> .\nl.ps1
`n
2
1