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.
Internationalised Domain Names (IDNs) is the term used for Internet domain names written using local languages and scripts. All characters which are not one of the 26 letters of the English alphabet, the numbers 0-9 or a hyphen (minus sign) are treated as IDN characters.
IDN domains, unlike regular domains, are encoded using a special encoding scheme called Punycode. Punycode converts the non-English-language characters into a series of letters that stand in for the non-English character. You can recognize an IDN domain in its raw form because you'll see an "xn--" in front of it.
When you wish to register an IDN, you first must encode it using the Punycode system and then register that encoded version. When the user enters the URL in its browser bar containing IDN, the browser first converts the IDN into Punycode and then resolves the domain.
What is Punycode? Punycode. noun. Unicode that converts words that cannot be written in ASCII, like the Greek word for thank you 'ευχαριστώ' into an ASCII encoding, like 'xn--mxahn5algcq2e' for use as domain names.
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
using System.Globalization;
...
IdnMapping idn = new IdnMapping();
MessageBox.Show(idn.GetAscii("www.kraków.pl"));
Have a look at the GNU IDN Library - Libidn. The introduction says that C# libraries are available.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With