PowerTip: Remove First Two Letters of String

Summary: Learn how to use Windows PowerShell remove the first two letters from a string.

Hey, Scripting Guy! Question How can I use Windows PowerShell to remove the first two letters from a string?

Hey, Scripting Guy! Answer Use the SubString method, for example:

$a = “String”


Comments (9)

  1. mredwilson says:

    @tester thanks, I just modified the title as well.

  2. mredwilson says:

    @all Sorry, I was typing faster than I was thinking. The code above is correct, and yes, I did test it. What I did not do was proof read very well. I wanted to REMOVE the first two letters, which is what the code does. Sorry for the confusion. I have updated
    the posting now to reflect my actual intent. Thanks for pointing this out to me.

  3. Gotta agree with the other comments here 🙂

  4. No, thank you, it was fun to find a typo. 🙂 Might I suggest a "What’s wrong with this command" series? It might be fun to work on a PowerShell bug or two and learn something in the process.

  5. solve2x says:

    Should it not be $a.substring(0,2) ?

  6. CareBearStare says:

    "{0}{1}" -f $a[0],$a[1]

  7. tester says:

    Did you test this solution?

  8. tester says:

    The subject line also needs to be modified to be consistent with the rest of the article.

Skip to main content