如何从 PowerShell 获取换行符中的字节数?
How can I get the number of bytes in a newline from PowerShell?
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 return 结果相同。
PS C:\src\t> .\nl.ps1
`n
2
1
.NET Standard 有一个 API,并且始终可以从 Powershell 获得:
[system.environment]::newline.length
在 Windows
PS> [system.environment]::newline.length
2
在 Ubuntu
PS> [system.environment]::newline.length
1
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 return 结果相同。
PS C:\src\t> .\nl.ps1
`n
2
1
.NET Standard 有一个 API,并且始终可以从 Powershell 获得:
[system.environment]::newline.length
在 Windows
PS> [system.environment]::newline.length
2
在 Ubuntu
PS> [system.environment]::newline.length
1