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

Using .split more than once on a string

Closed Thread
 
Thread Tools Display Modes
Old 02-08-2007   #1 (permalink)
Marco Shaw
Guest


 

Using .split more than once on a string

Can't I do this?

Trying to do $a.split('/').split('.').

Tried using extra parenthesis with no luck...

127> $a
http://powergadgets.com/csPg/forums/thread/218.aspx
[Feed:\powershell\powergadgets]
128> $a.split('/')
http:

powergadgets.com
csPg
forums
thread
218.aspx
[Feed:\powershell\powergadgets]
129> $a.split('/').split('.')
Method invocation failed because [System.String[]] doesn't contain a method
named 'split'.
At line:1 char:20
+ $a.split('/').split( <<<< '.')
[Feed:\powershell\powergadgets]
130> $a.split('/')|gm


TypeName: System.String

Name MemberType Definition
---- ---------- ----------
[snip]
Split Method System.String[] Split(Params Char[]
separator), System.String[] Split(Char[] ...


Old 02-08-2007   #2 (permalink)
mabster
Guest


 

Re: Using .split more than once on a string

Pass both split characters into the Split() call, Marco, like this:

$a.Split('/.')

Cheers,
Matt

"Marco Shaw" <marcoDOTshaw_@_gmailDOTcom> wrote in message
news:O8Gdb6#SHHA.4872@TK2MSFTNGP03.phx.gbl...
> Can't I do this?
>
> Trying to do $a.split('/').split('.').
>
> Tried using extra parenthesis with no luck...
>
> 127> $a
> http://powergadgets.com/csPg/forums/thread/218.aspx
> [Feed:\powershell\powergadgets]
> 128> $a.split('/')
> http:
>
> powergadgets.com
> csPg
> forums
> thread
> 218.aspx
> [Feed:\powershell\powergadgets]
> 129> $a.split('/').split('.')
> Method invocation failed because [System.String[]] doesn't contain a
> method named 'split'.
> At line:1 char:20
> + $a.split('/').split( <<<< '.')
> [Feed:\powershell\powergadgets]
> 130> $a.split('/')|gm
>
>
> TypeName: System.String
>
> Name MemberType Definition
> ---- ---------- ----------
> [snip]
> Split Method System.String[] Split(Params Char[]
> separator), System.String[] Split(Char[] ...
>

Old 02-08-2007   #3 (permalink)
Brandon Shell
Guest


 

Re: Using .split more than once on a string

Are you trying to do this?
($a.split("/")[2]).split(".")

When you split you get an array. You have to decide with of the array
elements you want to split again.

This may do what you want... what is it you are wanting?
$a.split("/") | %{if($_ -match "\."){$_.Split('.')}}

--
Brandon Shell
---------------
Stop by my blog some time
http://www.bsonposh.com/
Try the "Search of Powershell Blogs"
--------------------------------------
"Marco Shaw" <marcoDOTshaw_@_gmailDOTcom> wrote in message
news:O8Gdb6%23SHHA.4872@TK2MSFTNGP03.phx.gbl...
> Can't I do this?
>
> Trying to do $a.split('/').split('.').
>
> Tried using extra parenthesis with no luck...
>
> 127> $a
> http://powergadgets.com/csPg/forums/thread/218.aspx
> [Feed:\powershell\powergadgets]
> 128> $a.split('/')
> http:
>
> powergadgets.com
> csPg
> forums
> thread
> 218.aspx
> [Feed:\powershell\powergadgets]
> 129> $a.split('/').split('.')
> Method invocation failed because [System.String[]] doesn't contain a
> method named 'split'.
> At line:1 char:20
> + $a.split('/').split( <<<< '.')
> [Feed:\powershell\powergadgets]
> 130> $a.split('/')|gm
>
>
> TypeName: System.String
>
> Name MemberType Definition
> ---- ---------- ----------
> [snip]
> Split Method System.String[] Split(Params Char[]
> separator), System.String[] Split(Char[] ...
>


Old 02-08-2007   #4 (permalink)
Brandon Shell
Guest


 

Re: Using .split more than once on a string

Wow... thats spiffy... much easier than my way... Man I love Powershell.

--
Brandon Shell
---------------
Stop by my blog some time
http://www.bsonposh.com/
Try the "Search of Powershell Blogs"
--------------------------------------
"mabster" <mabster@madprops.org> wrote in message
news:128F9FC7-64CD-4E03-AF2C-BB2568738834@microsoft.com...
> Pass both split characters into the Split() call, Marco, like this:
>
> $a.Split('/.')
>
> Cheers,
> Matt
>
> "Marco Shaw" <marcoDOTshaw_@_gmailDOTcom> wrote in message
> news:O8Gdb6#SHHA.4872@TK2MSFTNGP03.phx.gbl...
>> Can't I do this?
>>
>> Trying to do $a.split('/').split('.').
>>
>> Tried using extra parenthesis with no luck...
>>
>> 127> $a
>> http://powergadgets.com/csPg/forums/thread/218.aspx
>> [Feed:\powershell\powergadgets]
>> 128> $a.split('/')
>> http:
>>
>> powergadgets.com
>> csPg
>> forums
>> thread
>> 218.aspx
>> [Feed:\powershell\powergadgets]
>> 129> $a.split('/').split('.')
>> Method invocation failed because [System.String[]] doesn't contain a
>> method named 'split'.
>> At line:1 char:20
>> + $a.split('/').split( <<<< '.')
>> [Feed:\powershell\powergadgets]
>> 130> $a.split('/')|gm
>>
>>
>> TypeName: System.String
>>
>> Name MemberType Definition
>> ---- ---------- ----------
>> [snip]
>> Split Method System.String[] Split(Params
>> Char[] separator), System.String[] Split(Char[] ...
>>


Old 02-08-2007   #5 (permalink)
William Stacey [C# MVP]
Guest


 

Re: Using .split more than once on a string

I give psh mad props. To be fair, however, we need to give the .Net
framework credit for that one (and all the other methods and properties).

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


"Brandon Shell" <tshell@mask.gmail.com> wrote in message
news:uSaHki$SHHA.2256@TK2MSFTNGP02.phx.gbl...
| Wow... thats spiffy... much easier than my way... Man I love Powershell.
|
| --
| Brandon Shell
| ---------------
| Stop by my blog some time
| http://www.bsonposh.com/
| Try the "Search of Powershell Blogs"
| --------------------------------------
| "mabster" <mabster@madprops.org> wrote in message
| news:128F9FC7-64CD-4E03-AF2C-BB2568738834@microsoft.com...
| > Pass both split characters into the Split() call, Marco, like this:
| >
| > $a.Split('/.')
| >
| > Cheers,
| > Matt
| >
| > "Marco Shaw" <marcoDOTshaw_@_gmailDOTcom> wrote in message
| > news:O8Gdb6#SHHA.4872@TK2MSFTNGP03.phx.gbl...
| >> Can't I do this?
| >>
| >> Trying to do $a.split('/').split('.').
| >>
| >> Tried using extra parenthesis with no luck...
| >>
| >> 127> $a
| >> http://powergadgets.com/csPg/forums/thread/218.aspx
| >> [Feed:\powershell\powergadgets]
| >> 128> $a.split('/')
| >> http:
| >>
| >> powergadgets.com
| >> csPg
| >> forums
| >> thread
| >> 218.aspx
| >> [Feed:\powershell\powergadgets]
| >> 129> $a.split('/').split('.')
| >> Method invocation failed because [System.String[]] doesn't contain a
| >> method named 'split'.
| >> At line:1 char:20
| >> + $a.split('/').split( <<<< '.')
| >> [Feed:\powershell\powergadgets]
| >> 130> $a.split('/')|gm
| >>
| >>
| >> TypeName: System.String
| >>
| >> Name MemberType Definition
| >> ---- ---------- ----------
| >> [snip]
| >> Split Method System.String[] Split(Params
| >> Char[] separator), System.String[] Split(Char[] ...
| >>
|


Old 02-08-2007   #6 (permalink)
Brandon Shell
Guest


 

Re: Using .split more than once on a string

I should have clarified my point.. I meant because there is so many ways to
do the same thing and there always seems to be an easier way

--
Brandon Shell
---------------
Stop by my blog some time
http://www.bsonposh.com/
Try the "Search of Powershell Blogs"
--------------------------------------
"William Stacey [C# MVP]" <william.stacey@gmail.com> wrote in message
news:u9bjA$$SHHA.5016@TK2MSFTNGP05.phx.gbl...
>I give psh mad props. To be fair, however, we need to give the .Net
> framework credit for that one (and all the other methods and properties).
>
>
> --
> William Stacey [C# MVP]
> PCR concurrency library: www.codeplex.com/pcr
> PSH Scripts Project www.codeplex.com/psobject
>
>
> "Brandon Shell" <tshell@mask.gmail.com> wrote in message
> news:uSaHki$SHHA.2256@TK2MSFTNGP02.phx.gbl...
> | Wow... thats spiffy... much easier than my way... Man I love Powershell.
> |
> | --
> | Brandon Shell
> | ---------------
> | Stop by my blog some time
> | http://www.bsonposh.com/
> | Try the "Search of Powershell Blogs"
> | --------------------------------------
> | "mabster" <mabster@madprops.org> wrote in message
> | news:128F9FC7-64CD-4E03-AF2C-BB2568738834@microsoft.com...
> | > Pass both split characters into the Split() call, Marco, like this:
> | >
> | > $a.Split('/.')
> | >
> | > Cheers,
> | > Matt
> | >
> | > "Marco Shaw" <marcoDOTshaw_@_gmailDOTcom> wrote in message
> | > news:O8Gdb6#SHHA.4872@TK2MSFTNGP03.phx.gbl...
> | >> Can't I do this?
> | >>
> | >> Trying to do $a.split('/').split('.').
> | >>
> | >> Tried using extra parenthesis with no luck...
> | >>
> | >> 127> $a
> | >> http://powergadgets.com/csPg/forums/thread/218.aspx
> | >> [Feed:\powershell\powergadgets]
> | >> 128> $a.split('/')
> | >> http:
> | >>
> | >> powergadgets.com
> | >> csPg
> | >> forums
> | >> thread
> | >> 218.aspx
> | >> [Feed:\powershell\powergadgets]
> | >> 129> $a.split('/').split('.')
> | >> Method invocation failed because [System.String[]] doesn't contain a
> | >> method named 'split'.
> | >> At line:1 char:20
> | >> + $a.split('/').split( <<<< '.')
> | >> [Feed:\powershell\powergadgets]
> | >> 130> $a.split('/')|gm
> | >>
> | >>
> | >> TypeName: System.String
> | >>
> | >> Name MemberType Definition
> | >> ---- ---------- ----------
> | >> [snip]
> | >> Split Method System.String[] Split(Params
> | >> Char[] separator), System.String[] Split(Char[] ...
> | >>
> |
>
>


Old 02-08-2007   #7 (permalink)
William Stacey [C# MVP]
Guest


 

Re: Using .split more than once on a string

Agreed. I just wanted to give the fx props for Split(). Cheers. :-)

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


"Brandon Shell" <tshell@mask.gmail.com> wrote in message
news:O7rDKbATHHA.3592@TK2MSFTNGP03.phx.gbl...
|I should have clarified my point.. I meant because there is so many ways to
| do the same thing and there always seems to be an easier way
|
| --
| Brandon Shell
| ---------------
| Stop by my blog some time
| http://www.bsonposh.com/
| Try the "Search of Powershell Blogs"
| --------------------------------------
| "William Stacey [C# MVP]" <william.stacey@gmail.com> wrote in message
| news:u9bjA$$SHHA.5016@TK2MSFTNGP05.phx.gbl...
| >I give psh mad props. To be fair, however, we need to give the .Net
| > framework credit for that one (and all the other methods and
properties).
| >
| >
| > --
| > William Stacey [C# MVP]
| > PCR concurrency library: www.codeplex.com/pcr
| > PSH Scripts Project www.codeplex.com/psobject
| >
| >
| > "Brandon Shell" <tshell@mask.gmail.com> wrote in message
| > news:uSaHki$SHHA.2256@TK2MSFTNGP02.phx.gbl...
| > | Wow... thats spiffy... much easier than my way... Man I love
Powershell.
| > |
| > | --
| > | Brandon Shell
| > | ---------------
| > | Stop by my blog some time
| > | http://www.bsonposh.com/
| > | Try the "Search of Powershell Blogs"
| > | --------------------------------------
| > | "mabster" <mabster@madprops.org> wrote in message
| > | news:128F9FC7-64CD-4E03-AF2C-BB2568738834@microsoft.com...
| > | > Pass both split characters into the Split() call, Marco, like this:
| > | >
| > | > $a.Split('/.')
| > | >
| > | > Cheers,
| > | > Matt
| > | >
| > | > "Marco Shaw" <marcoDOTshaw_@_gmailDOTcom> wrote in message
| > | > news:O8Gdb6#SHHA.4872@TK2MSFTNGP03.phx.gbl...
| > | >> Can't I do this?
| > | >>
| > | >> Trying to do $a.split('/').split('.').
| > | >>
| > | >> Tried using extra parenthesis with no luck...
| > | >>
| > | >> 127> $a
| > | >> http://powergadgets.com/csPg/forums/thread/218.aspx
| > | >> [Feed:\powershell\powergadgets]
| > | >> 128> $a.split('/')
| > | >> http:
| > | >>
| > | >> powergadgets.com
| > | >> csPg
| > | >> forums
| > | >> thread
| > | >> 218.aspx
| > | >> [Feed:\powershell\powergadgets]
| > | >> 129> $a.split('/').split('.')
| > | >> Method invocation failed because [System.String[]] doesn't contain
a
| > | >> method named 'split'.
| > | >> At line:1 char:20
| > | >> + $a.split('/').split( <<<< '.')
| > | >> [Feed:\powershell\powergadgets]
| > | >> 130> $a.split('/')|gm
| > | >>
| > | >>
| > | >> TypeName: System.String
| > | >>
| > | >> Name MemberType Definition
| > | >> ---- ---------- ----------
| > | >> [snip]
| > | >> Split Method System.String[] Split(Params
| > | >> Char[] separator), System.String[] Split(Char[] ...
| > | >>
| > |
| >
| >
|


Closed Thread

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Find a string within a variable string Edward.A.Gonzalez PowerShell 4 2 Weeks Ago 08:13 AM
problems with $var | select-string -pattern $string -q Ben Christian PowerShell 3 02-08-2008 12:41 PM
select-string and .split alicain PowerShell 3 10-12-2007 11:01 AM
How export-csv deals with string versus string[] Marco Shaw PowerShell 2 07-13-2007 12:18 PM
String PRODUCT_NAME was not found in string table Extracampine Vista General 3 02-12-2007 06:15 AM








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