12

What is the best way to convert an internationalized domain name to its ASCII-form?

I want to convert Bücher.ch into xn--bcher-kva.ch by using some sort of (free) .net code.

Espo
  • 41,399
  • 21
  • 132
  • 159

3 Answers3

37
using System.Globalization;
...
IdnMapping idn = new IdnMapping();
MessageBox.Show(idn.GetAscii("www.kraków.pl"));
Espo
  • 41,399
  • 21
  • 132
  • 159
adam
  • 371
  • 3
  • 2
6

To Get the other way around from xn--bcher-kva.ch domain to Bücher.ch

using System.Globalization;
...
IdnMapping idn = new IdnMapping();
MessageBox.Show(idn.GetUnicode("xn--bcher-kva.ch"));

You will get www.kraków.pl as result. Because i came here to look for this :) hope it is helpful for others as well :)

MSDN

Abdul Saboor
  • 4,079
  • 2
  • 33
  • 25
4

Have a look at the GNU IDN Library - Libidn. The introduction says that C# libraries are available.

dommer
  • 19,610
  • 14
  • 75
  • 137
  • 5
    -1 for suggesting a 3rd party library when .NET itself is capable of this. – Venemo Aug 12 '12 at 06:58
  • 2
    @Venemo The .NET library does not support all chars. [link](http://manage.resellerclub.com/kb/answer/1740) for example: **ß** is not supported. – Pumper Jan 05 '15 at 17:21