Quantcast
Channel: Hey, Scripting Guy! Blog
Viewing all articles
Browse latest Browse all 3333

PowerTip: Pad String to Left with PowerShell

$
0
0

Summary: Use Windows PowerShell to pad a string to the left.

Hey, Scripting Guy! Question How can I use a specific Unicode character with Windows PowerShell to pad a string to the left so that the entire
           string is a certain length?

Hey, Scripting Guy! Answer Use the PadLeft method from the String class. Specify the length of the newly created string and the Unicode
           character as the second parameter. Here is an example that uses a triangle as the pad character. The string is
           6 characters long, and the newly created string is 15 characters long. The padding will be 9 triangles.

PS C:\> $a = "string"

PS C:\> $a.PadLeft(15,[char]4)

♦♦♦♦♦♦♦♦♦string


Viewing all articles
Browse latest Browse all 3333

Trending Articles