SORU
27 Mayıs 2010, PERŞEMBE


C URL Slugify algoritması#?

Ve slug etiketi ile aranan göz var ve sadece iki zorlayıcı bir çözüm buldu:

Ancak bu soruna kısmi çözüm olan. El ile kendimi bu kod olabilir ama zaten bir çözüm orada henüz yok şaşırdım.

C slugify alrogithm bir uygulama var# ve/veya .Düzgün latin karakterler, unicode ve diğer çeşitli dil sorunları doğru adres NET?

CEVAP
27 Mayıs 2010, PERŞEMBE


http://predicatet.blogspot.com/2009/04/improved-c-slug-generator-or-how-to.html

public static string GenerateSlug(this string phrase) 
{ 
    string str = phrase.RemoveAccent().ToLower(); 
    // invalid chars           
    str = Regex.Replace(str, @"[^a-z0-9\s-]", ""); 
    // convert multiple spaces into one space   
    str = Regex.Replace(str, @"\s ", " ").Trim(); 
    // cut and trim 
    str = str.Substring(0, str.Length <= 45 ? str.Length : 45).Trim();   
    str = Regex.Replace(str, @"\s", "-"); // hyphens   
    return str; 
} 

public static string RemoveAccent(this string txt) 
{ 
    byte[] bytes = System.Text.Encoding.GetEncoding("Cyrillic").GetBytes(txt); 
    return System.Text.Encoding.ASCII.GetString(bytes); 
}

Bunu Paylaş:
  • Google+
  • E-Posta
Etiketler:

YORUMLAR

SPONSOR VİDEO

Rastgele Yazarlar

  • psidot

    psidot

    2 Kasım 2006
  • TechRax

    TechRax

    21 EYLÜL 2009
  • The CGBros

    The CGBros

    20 AĞUSTOS 2011