# encoding: ascii
# api: powershell
# title: Split-TextToLines Demo
# description: Demo of different ways to split a text into lines. Sorry I have not yet another nice way to post code in my blog. http://pauerschell.blogspot.com/. Understanding TextToLines splitting is basic to ISE-Extensions.
# version: 0.1
# type: function
# author: Bernd Kriszio
# license: CC0
# function: Show-LineArrayStructure
# x-poshcode-id: 883
# x-archived: 2016-06-08T10:20:49
# x-published: 2009-02-20T13:08:00
#
#
function Show-LineArrayStructure ($lines)
{
$len = $lines.length
"Type is: $($lines.gettype().Name)"
"Number of lines: $len"
for ($i = 0; $i -lt $len; $i++)
{
"$($i + 1). Line: length $($lines[$i].length) >$($lines[$i])<"
}
''
}
$text = "abc`r`nefg`r`n"
# $text
# $text.length
$lines = $text.Split("`n")
Show-LineArrayStructure $lines
$lines2 = $text.Split("`r`n")
Show-LineArrayStructure $lines2
$lines3 = $([Regex]::Split($text,"`r`n" ))
Show-LineArrayStructure $lines3
$lines4 = $text -split "`n"
Show-LineArrayStructure $lines4
# best method
$lines5 = $text -split "`r`n"
Show-LineArrayStructure $lines5