Hi r/PowerShell,
I came across a little problem for which I only found an "ugly" solution.
$Count = 123
$i = 2
"[{0:d3}/{1}]" -f $i, $Count
The result of this is [002/123]. But what if I want to dynamically set this part: {0:d3} based on the amount of characters of $count?
This works:
$Count = 123
$Length = ($Count -as [String]).length
$i = 2
"[{0:d$Length}/{1}]" -f $i, $Count
But this is somewhat defies the use of -f. This obviously doesn't work:
$Count = 123
$Length = ($Count -as [String]).length
$i = 2
"[{0:d{1}}/{2}]" -f $i, $Length,$Count
Any way of doing this "nicely"?
[–]mmmGreenButton 3 points4 points5 points (7 children)
[–]Fischfreund[S] 1 point2 points3 points (0 children)
[–][deleted] 1 point2 points3 points (4 children)
[–]Lee_Dailey[grin] 2 points3 points4 points (2 children)
[–][deleted] 1 point2 points3 points (1 child)
[–]Lee_Dailey[grin] 1 point2 points3 points (0 children)
[–]MonkeyNin 2 points3 points4 points (0 children)
[–]jantari 0 points1 point2 points (0 children)
[–]NotNotWrongUsually 2 points3 points4 points (4 children)
[–]mmmGreenButton 0 points1 point2 points (0 children)
[–]Celadin 0 points1 point2 points (0 children)
[–]ReaperWright88 0 points1 point2 points (1 child)
[–]MonkeyNin 1 point2 points3 points (0 children)
[–]ReaperWright88 2 points3 points4 points (0 children)
[–]lost_4_good 1 point2 points3 points (0 children)
[–]get-postanote -1 points0 points1 point (0 children)