Eggins.com
Powershell, .Net, Visual Studio, Team Foundation Server, Windows Communication Foundation

Powershell String Formatting

Powershell uses the .Net string formatting features in String.Format. The only formatting functionality for a string is the alignment.

To left align a string and pad to 40 chars, the following two lines produce the same result:

  [System.String]::Format("{0,-40}", "MTB rules")
  "{0,-40}" -f "MTB Rules"

 

To right align a string and pad to 40 chars, the following two lines produce the same result:

[System.String]::Format("{0,40}", "MTB rules")
  "{0,40}" -f "MTB Rules"

Here is a more complex example:
  "{0,-40} flies like a {1,40}" -f "Fruit", "Bannana"
Produces (without the quotes):
  "Fruit        flies like a        Bannana"
 

More details on the full range of format specifier strings here:
   http://eggins.com/files/folders/103/download.aspx

 


Posted May 17 2007, 05:28 PM by David

Add a Comment

(required)  
(optional)
(required)  
Remember Me?
Copyright eggins.com, 1998 - 2008
Powered by Community Server (Non-Commercial Edition), by Telligent Systems