# 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: 886
# x-derived-from-id: 3201
# x-archived: 2016-07-08T10:32:20
# x-published: 2009-02-21T10:31: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
# even better proposed by Jaycul in comment on
# http://pauerschell.blogspot.com/2009/02/ise-extension-basics-splitting-text-to.html
$lines6 =$text.Split([string[]]"`r`n", [StringSplitOptions]::None)
Show-LineArrayStructure $lines6