PowerShell SubString with Examples

In Windows PowerShell, you can perform a substring operation using the SubString() method.

Let's take a look at a few examples.

Example 1: One-Liner SubString

    echo "Welcome to Code2care!".SubString(11)

    Output:

    Code2care!


    echo "Welcome to Code2care!".SubString(0,7)

    Output:

    Welcome


Example 2: SubString with Script

    $string = "PowerShell is Fun!"
    $substring = $string.SubString(0,10)
    echo $substring

    PS> ./powershell-script.ps1


    PowerShell
PowerShell SubString Example

Comments & Discussion

Facing issues? Have questions? Post them here! We're happy to help!