What is the best way, in .NET, to create safe URLs from titles of posts?
For example, I may have a post "test wıth non enğlİşh çharaçters" and I want to turn this into a URL safe form while still maintaining the readability purpose of the title being URL, such as, "test-with-non-english-characters", and I will use them as http://mysite/blog/5/test-with-non-english-characters I can just iterate over the string characters and either leave ALL letters as they are (not safe to use in URLs), or wipe out all non-English characters and turn them into an underscore etc. (breaks the purpose of readability, as posts will/may be in non English languages). I'm sure that there's a method for converting ş
to s
and Ğ
to G
etc. just like in an accent insensitive search query in SQL server.
Asked
Active
Viewed 960 times
2

Can Poyrazoğlu
- 33,241
- 48
- 191
- 389
-
3This is probably a losing battle. What lowercase letters does ڟﻌ▓░♀☺╩ۆ correspond to? – Rag Aug 18 '11 at 15:15
-
they would be removed. anything that doesn't have an accent insensitive mapping to a letter in the English alphabet would obviously be removed, I don't think I need to say that explicitly. – Can Poyrazoğlu Aug 18 '11 at 15:26
1 Answers
2
See my answer to another question to remove accents from a string.
Note that this doesn't completely solve the problem. For example, Asian ideograms or non latin letters will not be transliterated to english (latin) letters using this code.

Community
- 1
- 1

Serge Wautier
- 21,494
- 13
- 69
- 110
-
for now, just latin accent removal is enough for me. i didn't know about the `Normalize` method, i think it will work for me.. – Can Poyrazoğlu Aug 18 '11 at 15:32