Developer forum

Forum » CMS - Standard features » Replacing invalid url chars

Replacing invalid url chars

Peter Leleulya
Reply

Hi guys,

Of course I know of UrlEncode, but I noticed the Dynamicweb Url handler interprets ë, ö, etc and converts them in readable variations of that character in stead of %3cwhatever encoding.
I need to auto generate sub domain bindings based on strings and was wondering if whatever functionality is handling the interpretation of these characters is accessable through the dynamicweb dlls ...
I already filtered all common keybord chars by regex and do an urlencode at the end to be sure i have a valid subdomain.
But I'm stuck with these characters which must be so common for you guys up north ... They get terriblyuglified by the encoding ...
Any tips?

Greetings, Peter.


Replies

 
Peter Leleulya
Reply

Never mind, as soon as I discovered the correct word for these accents is "diacritics", a simple solution was quickly found:

public static string RemoveDiacritics(string text)
        {
            var normalizedString = text.Normalize(NormalizationForm.FormD);
            var stringBuilder = new StringBuilder();
            foreach (var c in from c in normalizedString let unicodeCategory = CharUnicodeInfo.GetUnicodeCategory(c) where unicodeCategory != UnicodeCategory.NonSpacingMark select c)
            {
                stringBuilder.Append(c);
            }
            return stringBuilder.ToString().Normalize(NormalizationForm.FormC);
        }

 

You must be logged in to post in the forum