Can Poyrazoğlu
Can Poyrazoğlu

Reputation: 34830

Sanitizing non-English letters to use safely in URLs

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.

Upvotes: 2

Views: 998

Answers (1)

Serge Wautier
Serge Wautier

Reputation: 21898

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.

Upvotes: 2

Related Questions