ToUrlSlug

public static string ToUrlSlug(this string text)
{
return Regex.Replace(
            Regex.Replace(
                Regex.Replace(
                    text.Trim().ToLower()
                            .Replace("ö", "o")
                            .Replace("ç", "c")
                            .Replace("ş", "s")
                            .Replace("ı", "i")
                            .Replace("ğ", "g")
                            .Replace("ü", "u"),
                @"\s+", " "), // multiple spaces to one space
                @"\s", "-"), // spaces to hypens
                @"[^a-z0-9\s-]", ""); // removing invalid chars
}
Example:
var name = "Serdar Büyüktemiz çşğüİö";
var urlName = name.ToUrlSlug(); // returns serdar-buyuktemiz-csguio

Description

If you get Turkish inputs you can use this method to create url slugs

Details

Double click on the code to select all.

 

;