Reputation: 187
I have a csv file that has multiople lines, which uses "|" as delimiter as the following shows.
MAIN|02/21/2018|7695154880|082.21|00021
MAIN|02/21/2018|7695154880|000.21|00210
I would like to remove the leading zeros of forth and fifth sections so the following shows desired result. Is there any way can do it in powershell? Thank you.
MAIN|02/21/2018|7695154880|82.21|21
MAIN|02/21/2018|7695154880|0.21|210
Upvotes: 0
Views: 45
Reputation: 671
I initially thought Regex like [regex]::replace($value,'^(0+)','')
But - in my opinion it would be better just to do
$csv|Foreach-Object{$_.ValueTORemoveLeadingZeroesFrom=
[float]$_.ValueTORemoveLeadingZeroesFrom}
By casting string to float You actually get this done easier I think?
Upvotes: 0
Reputation: 16076
Agree with Olaf here, including the zero thing. Yet, maybe it's just the visual thing for you. Anyway, what you are asking for is similar to this post.
Remove leading zeros in csv file from int values only
I have this csv file I'm trying to remove leading zeros from
Upvotes: 1