Windows Vista Forums
Vista Forums Home Join Vista Forums Donate Vista Tutorials Tags

Welcome to Vista Forums we are your forum to discuss Windows Vista x64 and x86 systems. Whether you need help or just want to post an idea you have on Vista, this is the forum for you.
Register at Vista forums...the world biggest Windows Vista resource Join Vista Forums Now

Go Back   Vista Forums > Microsoft Technical Newsgroups > PowerShell

Perl split function equivalent

Closed Thread
 
Thread Tools Display Modes
Old 02-14-2007   #1 (permalink)
Frank
Guest


 

Perl split function equivalent

It is definate that PowerShell is very powerful with hooks to WMI and so
forth but it appears to be lacking of some string manipulation functions. I
am a newbie to PowerShell but I cannot find anything close to the Perl split.
I found a regex split but that isn't what I really needed. What I need is:

my ($f1,$f2) = split (/,/, $record);
my $total = $f2 + $count;

to split the fields delimeted by a comma, then I would like to deal only
with field two. Is this possible?

Thanks in advance


Old 02-14-2007   #2 (permalink)
William Stacey [C# MVP]
Guest


 

Re: Perl split function equivalent

PS C:\TEMP> $line = "one,3"
PS C:\TEMP> $total = $line.split(",")[1] + $count

--
William Stacey [C# MVP]
PCR concurrency library: www.codeplex.com/pcr
PSH Scripts Project www.codeplex.com/psobject


"Frank" <Frank@discussions.microsoft.com> wrote in message
news:F807C9A2-F28F-479C-88AA-C50AF166010D@microsoft.com...
| It is definate that PowerShell is very powerful with hooks to WMI and so
| forth but it appears to be lacking of some string manipulation functions.
I
| am a newbie to PowerShell but I cannot find anything close to the Perl
split.
| I found a regex split but that isn't what I really needed. What I need
is:
|
| my ($f1,$f2) = split (/,/, $record);
| my $total = $f2 + $count;
|
| to split the fields delimeted by a comma, then I would like to deal only
| with field two. Is this possible?
|
| Thanks in advance
|
|


Old 02-14-2007   #3 (permalink)
mikes.net
Guest


 

Re: Perl split function equivalent

Hi,

PS > "1,2,3".split(',')
1
2
3
PS > $a,$b = "1,2,3".split(',')
PS > $a
1
PS > $b
2
3
PS > $a + [Math]::Pi # Note $a was parsed as a string.
13.14159265358979
PS > [int]$a + [Math]::Pi
4.14159265358979
PS >

You will also want to read up on the -match and -replace
operators, which are sometimes convenient for pattern matching.

The most important cmdlet to know and use often is Get-Member. As
a Perl user the trickiest cmdlets for you will be Get-Content, Set-
Content, Get-ChildItem.

Mike


On Feb 14, 6:20 pm, Frank <F...@discussions.microsoft.com> wrote:
> It is definate that PowerShell is very powerful with hooks to WMI and so
> forth but it appears to be lacking of some string manipulation functions. I
> am a newbie to PowerShell but I cannot find anything close to the Perl split.
> I found a regex split but that isn't what I really needed. What I need is:
>
> my ($f1,$f2) = split (/,/, $record);
> my $total = $f2 + $count;
>
> to split the fields delimeted by a comma, then I would like to deal only
> with field two. Is this possible?
>
> Thanks in advance



Old 02-14-2007   #4 (permalink)
William Stacey [C# MVP]
Guest


 

Re: Perl split function equivalent


| PS > $a,$b = "1,2,3".split(',')

I love this little ditty. We need to keep in mind it does involve another
array alloc (and array copy) each time we do it. But I do like it soo.
--wjs


Closed Thread

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem using split function Meat VB Script 4 07-23-2008 11:25 AM
can I install Perl on Vista? anna Vista General 5 03-09-2008 02:09 PM
Split function IT Staff PowerShell 6 10-24-2007 01:48 PM
Is there an equivalent of the DOS pause function Fil PowerShell 3 11-22-2006 04:14 PM
What I think of the Office2007 and Vista Perl.... John Jay Smith Vista General 0 09-01-2006 01:42 PM








Vistax64.com is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media 2005-2008

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50