Posted By

ericmorin21 on 04/17/09


Tagged

Pad padding left-padding


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

Tyster


Left-padding in Powershell


 / Published in: Windows PowerShell
 

For clarity, I have broken two variables out, but this could easily be a one-liner. Usage: Replace X with the character you wish to use to pad (e.g. 0 (zero)). Replace Y with an integer representing the desired TOTAL length of the string.

  1. $padChar = "X"
  2. $paddedLength = Y
  3. $stringToPad = ($padChar * ($paddedLength - $stringToPad)) + $stringToPad

Report this snippet  

You need to login to post a comment.