Welcome to MSDN Blogs Sign in | Join | Help

PSMDTAG:FAQ: What is $OFS

In my blog entry regarding Cascading Type Casts ( http://blogs.msdn.com/powershell/archive/2006/07/15/Cascading_Type_Casts.aspx ) there was an example:

PS> [string][char[]][int[]][char[]]"PowerShell"
P o w e r S h e l l

And in a comment was a question asking why there were spaces between the letters.  The answer is $OFS

 

PSMDTAG:FAQ: What is $OFS

$OFS is a special variable that contains the string to be used as the Ouptut Field Sperator.   This string is used when an array is converted to a string.  By default, this is " " but you can change it.

Here are some examples to clarify:


PS> $a="1","2","3","4"
PS> $a
1
2
3
4
PS> [string]$a
1 2 3 4
PS> $OFS="";[string]$a
1234
PS> $OFS=",";[string]$a
1,2,3,4
PS> $OFS="--PowerShellRocks--";[string]$a
1--PowerShellRocks--2--PowerShellRocks--3--PowerShellRocks--4
PS> $OFS="`n`n";[string]$a
1


2


3


4
PS>

Experiment and Enjoy!

Jeffrey Snover [MSFT]
Windows PowerShell/Aspen Architect
Visit the Windows PowerShell Team blog at:    http://blogs.msdn.com/PowerShell
Visit the Windows PowerShell ScriptCenter at:  http://www.microsoft.com/technet/scriptcenter/hubs/msh.mspx

Published Saturday, July 15, 2006 11:02 PM by PowerShellTeam
Filed under: ,

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

# Powershell Using $OFS « A brooklyn Tale

Tuesday, May 05, 2009 9:07 PM by Powershell Using $OFS « A brooklyn Tale

Leave a Comment

(required) 
required 
(required) 
 
Page view tracker