15

I was just looking through some old posts and I noticed that a "ß" in a question title magically turns into an "ss" in the URL slug.

What function is being used to format the slugs? Clearly it has some advanced behavior in terms of determining character equivalents, rather than just ignoring special characters.

(Note: I just tried this with "fi" and "fl" and they're not converted to "fi" and "fl"...)

8
  • 6
    String url = post.Title.Replace("ß", "ss"); Commented Mar 28, 2012 at 20:45
  • +1 Oh.. I see what you did there :P (ß)
    – Lix
    Commented Mar 28, 2012 at 20:45
  • 8
    he co҉mè̑ͧ̌s
    – fredley
    Commented Mar 28, 2012 at 20:47
  • @fredley: Okay... String url = System.Text.RegularExpressions.RegEx.Replace(post.Title, "ß", "ss"); ... I might have those parameters reversed, though. Commented Mar 28, 2012 at 20:49
  • No way, unicode has ligatures?
    – Zelda
    Commented Mar 28, 2012 at 20:59
  • @BenBrocka - Unicode has the full complement of crazy pony stripes.
    – cdeszaq
    Commented Mar 28, 2012 at 21:22
  • 3
    @BenBrocka whenever I think about about ligature, diacritical, or digraph support in Unicode it makes me go CYRILLIC CAPITAL LETTER UK Commented Mar 28, 2012 at 21:36
  • possible duplicate of Non US-ASCII characters dropped from full (profile) URL
    – Cody Gray
    Commented Apr 2, 2012 at 1:25

1 Answer 1

11

Assuming the current implementation is still similar (although Jeff mentions looking into another approach)...

Taking 80 characters from the raw title, , ,, ., /, \, and _ are replaced with -, collapsing consecutive such characters into a single dash. Latin alphabetic characters are converted to lowercase, and the following substitutions are made:

àåáâäãåą => a
èéêëę    => e
ìíîïı    => i
òóôõöø   => o
ùúûü     => u
çćč      => c
żźž      => z
śşš      => s
ñń       => n
ýŸ       => y
ł        => l
đ        => d
ß        => ss
ğ        => g
Þ        => th
ĥ        => h
ĵ        => j

Finally, if the above process resulted in the trailing dash, it is removed.

6
  • Only these particular substitutions? Is there not some library function which can de-adorn any Latin-ish character?
    – jtbandes
    Commented Mar 28, 2012 at 21:11
  • Do you describe an observation, or do you know the actual algorithm? Commented Mar 28, 2012 at 21:15
  • 4
    TIM STONE KNOWS ALL @CodeInChaos Commented Mar 28, 2012 at 21:17
  • I would have used something like s.Normalize(NormalizationForm.FormD).Where(c=>CharUnicodeInfo.GetUnicodeCategory(c)!=UnicodeCategory.NonSpacingMark); to get rid of diacritics. Which would not have handles ß. Commented Mar 28, 2012 at 21:17
  • 5
    See Jeff's answer in Non US-ASCII characters dropped from full (profile) URL, @jtbandes.
    – Arjan
    Commented Mar 28, 2012 at 21:19
  • @Arjan Ah, that's more up-to-date than where I was pulling the list from, good stuff.
    – Tim Stone
    Commented Mar 28, 2012 at 21:28

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .