Remove-Characters

This little function lets you remove characters from a string. The twist is that it takes a character array, and will remove all characters in it from the input string.

This can come in handy if you need to for instance remove all special characters from a string. Please note that I have added a selection of special characters as default value for the Remove parameter.

If you take it for a spin, I’d love to hear your comments about it.

3 comments

  1. Hi Øyvind,

    Maybe I’m missing the point, but couldn’t you rather use something like the below instead?:

    [char[]]$Remove = ‘!”#¤%&€/()=?`+[]{}@£$\¨^~*-_.:,;’
    $inputstring = ‘test!”#¤%&€/()##=?`+[]test{}@£$\¨^~*+*-_.:,;test’
    $InputString -replace “$([regex]::Escape($Remove).Replace(‘\ ‘,’|’))”, ”

    Like

    1. Hi Dirk. Thanks for your comment. You most certainly could. That’s the beauty of it isn’t it? Many ways to Rome and all that 🙂 The reason I didn’t use regex was just performance really. I have read that using regex will take quite a bit longer, but you will hardly notice it unless you try it on a really large string.

      Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s