New filters on the Home Feed, take a look!
view details

This post has been de-listed

It is no longer included in search results and normal feeds (front page, hot posts, subreddit posts, etc). It remains visible only via the author's post history.

6
Powershell dynamic string formatting
Post Body

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"?

Author
Account Strength
90%
Account Age
15 years
Verified Email
Yes
Verified Flair
No
Total Karma
4,540
Link Karma
3,347
Comment Karma
1,193
Profile updated: 4 days ago
Posts updated: 6 months ago

Subreddit

Post Details

We try to extract some basic information from the post title. This is not always successful or accurate, please use your best judgement and compare these values to the post title and body for confirmation.
Posted
4 years ago