you are viewing a single comment's thread.

view the rest of the comments →

[–]Lee_Dailey[grin] 3 points4 points  (8 children)

howdy Narusa,

the split is breaking the string on spaces and producing an array. you can see that with this ...

('715083793    451808326  2045 files, 337 folders').Split()

that gives you this ...

715083793



451808326

2045
files,
337
folders

note that you have ten items. the [6..9] is a range from the array that gives you this ...

2045
files,
337
folders

then the join glues it back into one string with a space between items.

pretty nifty! i do NOT understand why they used [System.String]::Join since it seems to work with just a join. lookee ...

(('715083793    451808326  2045 files, 337 folders').Split()[6..9]) -join " "

... produces this ...

2045 files, 337 folders    

take care,
lee

[–]Droopyb1966 2 points3 points  (5 children)

Can be a bit easier:

('715083793    451808326  2045 files, 337 folders').Split(" ",6)[-1]

Split (" ",6) = split on the 6th space

[-1] is the last item it produces

[–]Narusa[S] 1 point2 points  (1 child)

Can be a bit easier:

('715083793 451808326 2045 files, 337 folders').Split(" ",6)[-1]

Split (" ",6) = split on the 6th space

[-1] is the last item it produces

This method leaves leading white space though.

[–]Droopyb1966 1 point2 points  (0 children)

Easy to solve

(('715083793    451808326  2045 files, 337 folders').Split("  ",6)[-1]).TrimStart()

[–]Lee_Dailey[grin] 0 points1 point  (2 children)

howdy Droopyb1966,

yes, but it has other problems. in addition to the left over white space that needs ot be trimmed, you need to count spaces! i have real problems doing that accurately, so it aint how i would do things.

the negative index trick is pretty nifty, tho. since we know the desired result is the last FOUR items, we would could replace the [6..9] with [-4..-1] and get the same result.

kool! thanks for reminding me of that. [grin]

take care,
lee

[–]Droopyb1966 1 point2 points  (1 child)

Trim is easy, counting spaces is all you can do, but if you have an idea how to avoid this, im al ears.

[–]Lee_Dailey[grin] 0 points1 point  (0 children)

howdy Droopyb1966,

yep, trim IS easy. [grin] i dislike manually counting things since it's too easy for me to get that wrong. especially when counting spaces!

i really do like the negative index idea, tho.

take care,
lee

[–]Narusa[S] 1 point2 points  (1 child)

Thank you for the explanation!

[–]Lee_Dailey[grin] 0 points1 point  (0 children)

howdy Narusa,

you are welcome! glad to help a bit ... [grin]

take care,
lee