So I have searched and browsed through the slug tag on SO and only found two compelling solution:
Which are but partial solution to the problem. I could manually code this up myself but I'm surprised that there isn't already a solution out there yet.
So, is there a slugify alrogithm implementation in C# and/or .NET that properly address latin characters, unicode and various other language issues properly?
Here you find a way to generate url slug in c#. This function remove all accents(Marcel's answer), replace spaces, remove invalid chars, trim dashes from end and replace double occurences of "-" or "_"
Code:
Here is my rendition, based Joan's and Marcel's answers. The changes I made are as follows:
Here is the code:
This still does not solve the non-latin character issue. A completely alternative solution would be to use Uri.EscapeDataString to convert the the string its hex representation:
Then use the data to generate a hyperlink:
Many browsers will display Chinese characters in the address bar (see below), but based on my limited testing, it is not completely supported.
NOTE: In order for Uri.EscapeDataString to work this way, iriParsing must be enabled.
EDIT
For those looking to generate URL Slugs in C#, I recommend checking out this related question:
How does Stack Overflow generate its SEO-friendly URLs?
It is what I ended up using for my project.
One problem I've had with slugification (new word!) is collisions. If I have a blog post, for instance, called "Stack-Overflow" and one called "Stack Overflow", the slugs of those two titles are the same. Therefore, my slug generator usually has to involve the database in some way. This might be why you don't see more generic solutions out there.
http://predicatet.blogspot.com/2009/04/improved-c-slug-generator-or-how-to.html
Here is my shot at it. It supports:
Code: