Powershell - .split

时间:2017-07-22 16:54:50

标签: powershell powershell-v4.0

任何人都可以通过给出以下示例来解释string.split的奇怪行为。

# produces output that appears to split on "n" rather than the newline character
(ls alias: | Out-String).Split("\n")

# produces output that appears to split on "r" or "n" rather than the windows newline characters
(ls alias: | Out-String).Split("\r\n")

# produces output where each item is separated by a newline
(ls alias: | Out-String).Split([environment]::NewLine)

# produces the desired result
(ls alias: | Out-String) -split "\n"
# or
(ls alias: | Out-String) -split "\r\n"

我理解“\ r \ n”和“\ n”之间的区别。我遇到了-split和.Split()之间的区别。我似乎无法找到答案。

0 个答案:

没有答案