header
header Register : : Login header
header
divider
menuleft
menuright
submenu
left

We have a new sponsor!  Introducting Pragma Systems.  See the home page for details.

Push or Pop the first element of an array
Last Post 02 Feb 2010 10:04 PM by cameronove. 0 Replies.
Printer Friendly
Sort:
PrevPrev NextNext
You are not authorized to post a reply.
Author Messages
cameronoveUser is Offline
Basic Member
Basic Member
Posts:224
Avatar

--
02 Feb 2010 10:04 PM  
No question, just sharing...having a little fun with arrays.  Maybe you'll find it useful.  A couple of little functions that show the diversity of PowerShell.  Some of this is a lot like Python.  It's just too cool what you can do in PowerShell.

$myarray = 'Mr.','John','Smith'
$newarray = Pop-Array $myarray

-or-

$mypercentarray = '90%','75%','40%'
$mynewpercentarray = Pop-Array $mypercentarray -delimiter ~

-or-

$addgreetingtoarray = Push-Array Hello $myarray
function Pop-Array([System.Array]$PopArray,[string]$Delimiter='%'){            
    return ([string]::join($Delimiter,($PopArray[1..($PopArray.length-1)]))).split($Delimiter)            
}            
                
function Push-Array($Element = $null,[System.Array]$PushArray,[string]$Delimiter='%'){            
    return ("$Element$Delimiter$([string]::join($Delimiter,$PushArray))").split($Delimiter)            
}
Cameron
You are not authorized to post a reply.

Active Forums 4.1
right
   
footer Sponsored by Quest Software • SAPIEN Technologies • Compellent • Microsoft Windows Server 2008 footer
footer