PS
Powershell Tutorial Online

PowerShell and Basic String Formatting

There are several ways to work with string in powershell.

Scenario 1: Use static Format method
The System.String .NET Framework class has a Format static method that accepts composite formatting techniques. Some times you you have use string with variable values in some sort of operation like combining string and create one path


        PS C:\> [string]$file = 'file.txt'
        PS C:\> [string]::Format("c:\test{0}",$file)
        c:\test\file.txt

Scenario 2: Use the Format operator "-f "

        PS C:\> [string]$file = 'file.txt'
        PS C:\> "c:\test\{0}" -f $file
        c:\test\file.txt

Scenario 3: Use an Expanding string here is last scenario use string with variable values in some sort of operation like combining string and create one path

    PS C:\> [string]$file = 'file.txt'
    PS C:\> "c:\test\$file"
    c:\test\file.txt
    


Tutorials