I’m using asp.net 4 and c#.
I have a string that can contains:
- Special Characters, like: !ӣ$%&/()/#
- Accented letters, like: àòèù
- Empty spaces, like: ” “(1 consecutive or more),
Example string:
#Hi this is rèally/ special strìng!!!
I would like to:
a) Remove all Special Characters, like:
Hi this is rèally special strìng
b) Convert all Accented letters to NON Accented letters, like:
Hi this is really special string
c) Remove all Empty spaces and replace theme with a dash (-), like:
Hi-this-is-really-special-string
My aim is to creating a string suitable for URL path for better SEO.
Any idea how to do it with Regular Expression or another techniques?
Thanks for your help on this!
Similar to mathieu’s answer, but more custom made for you requirements. This solution first strips special characters and diacritics from the input string, and then replaces whitespace with dashes:
See it in action at ideone.com.