View Single Post
Old 05-22-2007   #4 (permalink)
Frank
Guest


 
 

Re: split works much different than expected

Thanks everyone for responding. My last question is, the string I get left is:

"1603." in variable $code.

I want to remove the "." so I tried: $code = $code -replaced ".",""

but I get a blank variable. Can someone tell me why?

thanks,




"Jean" wrote:

> > Hi,
> >
> > I am trying to get the error codes from a file but split seems to work much
> > different than I expect. ie, my file error_log contains:
> >
> > cmd.exe exited on testserver with error code 1603.
> >
> > when I try to do a split ie.
> >
> > $testerr = get-content error_log | where($_ -match "error code"}
> > if ($testerr){
> > ($one,$two)=$testerr.split("error code")
> > "one: $one, two: $two"
> > }
> >
> > I get really strange output, like:
> >
> > one: ps, two: x . x : .......
> >
> > Can someone help with split?
> >
> > Thanks,

>
> See this thread :
>
> http://groups.google.com/group/micro...e96d7be3a45ff7
>
> When Split is used with one argument, argument is a Char not a String.
> To use a String as argument you could do something like:
>
> $testerr.Split([string[]]'error code',[StringSplitOptions]::None)
>
> Regards,
>
> --
> Jean - JMST
> Belgium
>
>
>

My System SpecsSystem Spec