none
measure and display character count per a line in array RRS feed

  • Question

  • Hey everyone thank you for your help. I don't know what is wrong with me today.  I know this is an easy question that i have solved be for but today I am just struggling. i want to display the # of characters per line in an array.

    $array | foreach { $_.lenght} 

    Tuesday, June 5, 2018 8:59 PM

Answers

  • If you  look at your original post you will see that you have spelled "length" wrong.


    \_(ツ)_/

    • Marked as answer by cmoneyg Wednesday, June 6, 2018 7:05 PM
    Tuesday, June 5, 2018 11:46 PM
  • Look at your last command. You misspelled "length."

    -- Bill Stewart [Bill_Stewart]

    • Marked as answer by cmoneyg Wednesday, June 6, 2018 7:04 PM
    Wednesday, June 6, 2018 2:44 PM
    Moderator

All replies

  • Yes.  That works.


    \_(ツ)_/

    Tuesday, June 5, 2018 9:13 PM
  • It just comes out blank. and the next PS C:\ appears.  I have verified that my array has data using 

    $array  and also $array | measure . So I kinda feel like I am losing my mind. any ideas?

    Tuesday, June 5, 2018 9:28 PM
  • You array is not an array of strings.


    \_(ツ)_/

    Tuesday, June 5, 2018 9:30 PM
  • This what I am doing. and not to be obtuse but isn't it still a string?  but ultimately I am trying to get all the results that are greater than 30 char. and shorten them to be less than 30.  I am trying to figure this out on my own. but I honestly am not skilled enough to understand what I am doing wrong. So long story short I appreciate your help and patience. and anything you can teach me along the way. 

    $test = gci |select-object -expandProperty name | Where-Object { $_.length -gt 30 }
    $test
    $testarray1 = $test -replace "...$" 
    $testarray1 |foreach {$_.lenght}

    Tuesday, June 5, 2018 9:44 PM
  • Works fine for me:

    PS D:\scripts> $test = gci |select-object -expandProperty name | Where-Object { $_.length -gt 30 }
    PS D:\scripts> $testarray1 = $test -replace "...$"
    PS D:\scripts> $testarray1 |foreach {$_.length}
    31
    28
    30
    PS D:\scripts>
    


    \_(ツ)_/

    Tuesday, June 5, 2018 10:07 PM
  • If you  look at your original post you will see that you have spelled "length" wrong.


    \_(ツ)_/

    • Marked as answer by cmoneyg Wednesday, June 6, 2018 7:05 PM
    Tuesday, June 5, 2018 11:46 PM
  • Sorry about just now getting a back to you. But this is weird so me copying what you wrote works but it looks exactly like what I had. So I don't know. mine is the top one yours is the bottom.  but I guess it is working for now.

    PS C:\testarray> $test = gci |select-object -expandProperty name | Where-Object { $_.length -gt 30 }
    PS C:\testarray> $testarray1 = $test -replace "...$"
    PS C:\testarray> $testarray1 |foreach {$_.lenght}
    PS C:\testarray>
    PS C:\testarray> $test = gci |select-object -expandProperty name | Where-Object { $_.length -gt 30 }
    PS C:\testarray> $testarray1 = $test -replace "...$"
    PS C:\testarray> $testarray1 |foreach {$_.length}
    42
    31
    28
    33
    29
    30
    PS C:\testarray>

    Wednesday, June 6, 2018 2:15 PM
  • Look at your last command. You misspelled "length."

    -- Bill Stewart [Bill_Stewart]

    • Marked as answer by cmoneyg Wednesday, June 6, 2018 7:04 PM
    Wednesday, June 6, 2018 2:44 PM
    Moderator
  • wow......
    Wednesday, June 6, 2018 7:04 PM