What is easiest way to remove all special characters from string using Powershell?
Of course regex, but here you can see how it works:
[System.Text.RegularExpressions.Regex]::Replace($Text,"[^1-9a-zA-Z_]"," ");
For example
PS C:\Users\Martin> [System.Text.RegularExpressions.Regex]::Replace("I got cool
n1ck%/\/\name($7&","[^1-9a-zA-Z_]"," ");
I got cool n1ck name
I am replacing special characters with space, however of course you can use whatever you want – typically “_”
4 comments:
Thanks for taking the time to share this. You saved me at least a couple of hours with this short blog post.
How to remove [] characters ?
Weakness of attitude becomes weakness of charater. See the link below for more info.
#character
www.ufgop.org
Reading your article is such a privilege. It does inspire me, I hope that you can share more positive thoughts. Visit my site too. The link is posted below.
n8fan.net
www.n8fan.net
Post a Comment