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 4 weeks, 1 day ago.

  • Author
    Posts
  • #79679

    jensne
    Participant

    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=https://blog.advids.co/20-small-business-marketing-video-examples/]Small Business Social Media Marketing[/url]

  • #80108

    Don Jones
    Keymaster

    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
      Participant

      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.