Windows Vista Forums
Vista Forums Home Join Vista Forums Webcasts Windows 7 Forum 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

Lenght property

Update your Vista Drivers Update Your Drivers Now!!
Closed Thread
 
Thread Tools Display Modes
Old 11-07-2006   #1 (permalink)
Marco Shaw
Guest


 

Lenght property

What am I missing here? Would ".lenght" not give me the number of elements?

PS C:\> echo "1" > test.1
PS C:\> echo "2" >> test.1
PS C:\> gc test.1
1
2
PS C:\> (gc test.1).lenght
PS C:\>

From the PSH user guide:
"Get-Content already treats the data read from the file as an array, with
one element per line of file content. You can confirm this by checking the
Length of the returned content: "



Marco



My System SpecsSystem Spec
Old 11-07-2006   #2 (permalink)
Jeffery Hicks
Guest


 

Re: Lenght property

On Tue, 7 Nov 2006 11:35:02 -0400, Marco Shaw wrote:

> What am I missing here? Would ".lenght" not give me the number of elements?
>
> PS C:\> echo "1" > test.1
> PS C:\> echo "2" >> test.1
> PS C:\> gc test.1
> 1
> 2
> PS C:\> (gc test.1).lenght
> PS C:\>
>
> From the PSH user guide:
> "Get-Content already treats the data read from the file as an array, with
> one element per line of file content. You can confirm this by checking the
> Length of the returned content: "
>
>
>
> Marco


It does. You just have a typo:

PS E:\temp> echo 1 >test.1
PS E:\temp> echo 2 >>test.1
PS E:\temp> gc test.1
1
2
PS E:\temp> (gc test.1).length
2
PS E:\temp>

--
Jeffery Hicks - www.ScriptingAnswers.com
SAPIEN Technologies - Scripting, Simplified. www.SAPIEN.com
Scripting books: www.SAPIENPress.com
My System SpecsSystem Spec
Old 11-07-2006   #3 (permalink)
Marco Shaw
Guest


 

Re: Lenght property

> It does. You just have a typo:

*sigh* Pardon my French...

If I had of been using PrimalScript... ;-)


My System SpecsSystem Spec
Old 11-07-2006   #4 (permalink)
Sung M Kim
Guest


 

Re: Lenght property


Marco Shaw wrote:
> > It does. You just have a typo:

>
> *sigh* Pardon my French...
>
> If I had of been using PrimalScript... ;-)


I consider "Length" to be a bit hard to type so I usually go with
"Count" alias property for accessing Length property.

$a = @(1,2,3)
,$a | gm
TypeName: System.Object[]

Name MemberType Definition
---- ---------- ----------
Count AliasProperty Count = Length


Not only Count looks more intuitive in your script,
it's less error prone than Lenght

My System SpecsSystem Spec
Old 11-07-2006   #5 (permalink)
Marco Shaw
Guest


 

Re: Lenght property

> ,$a | gm

Hmmm... How is "$a|gm" different from ",$a|gm"? I see it gives different
results. Not sure what "," does here...

> Not only Count looks more intuitive in your script,
> it's less error prone than Lenght


See, you did it too... ;-)


My System SpecsSystem Spec
Old 11-07-2006   #6 (permalink)
Sung M Kim
Guest


 

Re: Lenght property


Marco Shaw wrote:
> > ,$a | gm

>
> Hmmm... How is "$a|gm" different from ",$a|gm"? I see it gives different
> results. Not sure what "," does here...

"Get-Member" cmdlet takes all the types and displays only a distinct
type information.
Since "$a" contains values of type integers, doing "$a | gm" would
result in displaying member information for "Int32".
",$a | gm" uhm. i forgot exactly how it worked but it does about the
same job as
"gm -inputobject $a"

>
> > Not only Count looks more intuitive in your script,
> > it's less error prone than Lenght

>
> See, you did it too... ;-)

Bah! That was certainly unintentional.

My System SpecsSystem Spec
Old 11-07-2006   #7 (permalink)
Maximilian Hänel
Guest


 

Re: Lenght property

Hi Sung

> ",$a | gm" uhm. i forgot exactly how it worked but it does about the
> same job as
> "gm -inputobject $a"


if you write
$a=1,2,3
$a | gm
then PS takes each object (in this case integers) out of the $a array
and places it in the pipe. Hence gm gets 3 integers through the pipe. If
on the other hand you write this:

,$a | gm

then you actually pass an array of an integer array. In this case PS
passes the content of the array in the same way as before, but now the
content of the "outer array" is the int array so gm gets one array of
integers.

hth

Max
My System SpecsSystem Spec
Old 11-12-2006   #8 (permalink)
Alex K. Angelopoulos [MVP]
Guest


 

Re: Lenght property


"Sung M Kim" <DontBotherMeWithSpam@gmail.com> wrote in message
news:1162919122.719348.161590@f16g2000cwb.googlegroups.com...

> Not only Count looks more intuitive in your script,
> it's less error prone than Lenght


htat's hte truht.


My System SpecsSystem Spec
Old 11-12-2006   #9 (permalink)
dreeschkind
Guest


 

Re: Lenght property

Ahh, it makes me feel very good that I'm not the only one on earth who
suffers from Lenght!

--
greetings
dreeschkind

"Alex K. Angelopoulos [MVP]" wrote:

>
> "Sung M Kim" <DontBotherMeWithSpam@gmail.com> wrote in message
> news:1162919122.719348.161590@f16g2000cwb.googlegroups.com...
>
> > Not only Count looks more intuitive in your script,
> > it's less error prone than Lenght

>
> htat's hte truht.
>
>
>

My System SpecsSystem Spec
Old 11-13-2006   #10 (permalink)
Jean
Guest


 

Re: Lenght property

> htat's hte truht

Did you konw taht an epitmtxenareoin sowhs taht a txet is rabeldae if
olny fsrit and lsat ltertes of wodrs are in oderr ? :-)

--
Jean - JMST
Belgium


My System SpecsSystem Spec
Closed Thread

Thread Tools
Display Modes



Similar Threads
Thread Thread Starter Forum Replies Last Post
How do I use the property of a property? John Vottero PowerShell 2 07-28-2008 11:18 AM
Changing the lenght of one picture? Jen W. Vista music pictures video 0 06-24-2008 10:08 PM
Use my custom TypeDescriptor to obtains default Value on property inXAML Property Editor of Visual Studio 2008 azerty Avalon 0 04-14-2008 06:14 AM
Value under the CPU property? Cyberstorme PowerShell 2 01-10-2008 12:10 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 51