Transforming a string of text into an array

To continue on with the error report code which I started in the last post, I have now figured out how to break up my errpt.txt (get the text file) file into an array where each error is one element:

# This must current be run after
# $errorArray is initialized
# in the parent shell like this:
#
# PS> $errorArray = @();
# PS> type errpt.txt | . ./readerrpt.ps1
# PS> $errorArray[43]

$Line = ""
foreach ($element in $input)
{
    if($element -Match "-----------*")
    {
	$errorArray += , $Line
	    $errorArray.Count
	    $Line = ""
    }
    else
    {
	$Line += "$element`n"
    }
}

Leave a Reply

Your email address will not be published. Required fields are marked *