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