How can I remove a sequence of characters from the end of a string in PowerShell

This topic contains 2 replies, has 3 voices, and was last updated by  David Flores 8 months ago.

  • Author
  • #79679


    While strings have their own functions to trim characters they may not behave as expected. For example TrimEnd removes a sequence of characters from the end of a string however the emphasis is characters, i.e. it will remove any instance of those characters from the end of the string and not the string you specify. For example:

    I should have ended with folke but instead fol. The reason is it keeps removing each character in the string "joke" until it comes to a letter not in the string. Folke ends with ke so those characters are removed as well! Instead I like to use substring starting from the beginning of the string and then trimming when it finds the first occurrence of what I want to remove.

    For more you can check
    [url=]Small Business Social Media Marketing[/url]

  • #80108

    Don Jones

    Was there a question? There's nothing native to do this; you'll have to write your own string processing routine to accomplish this.

    • #80195

      David Flores

      Based on the link he posted, I think this is just a spam posting. Can't really even figure out what the post is purportedly asking.

You must be logged in to reply to this topic.