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

Facing issues? Have Questions? Post them here! I am happy to answer!

Author Info:

Rakesh (He/Him) has over 14+ years of experience in Web and Application development. He is the author of insightful How-To articles for Code2care.

Follow him on: X

You can also reach out to him via e-mail: rakesh@code2care.org

Copyright © Code2care 2024 | Privacy Policy | About Us | Contact Us | Sitemap