Coming soon - Get a detailed view of why an account is flagged as spam!
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.

19
Prepending a +/- sign when transforming an integer to a string
Post Body

Hi r/powershell,

I have an object with a method that transforms and emits one of its integer properties to a string, and prepends a sign.

$Object = [PsCustomObject] @{

    Input = [int]42

}

$MethodScriptblock = {

    "{0}$($this.Input)" -f $(if (-not ($this.Input).ToString().StartsWith('-')){' '})

}

Add-Member -MemberType ScriptMethod -InputObject $Object -Name OutString -Value $MethodScriptblock 

$Object.OutString()

It is already working, but I was wondering if there is a nicer way of doing this. You guys always come up with very elegant solutions :)

Thank you

Author
Account Strength
90%
Account Age
15 years
Verified Email
Yes
Verified Flair
No
Total Karma
4,545
Link Karma
3,347
Comment Karma
1,198
Profile updated: 2 days ago
Posts updated: 10 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
6 years ago