Searching...
Sunday, 6 October 2013

How to convert Unicode to ASCII in java ?

06:39

Java.net.IDN class Provides methods to convert internationalized domain names (IDNs) between a normal Unicode representation and an ASCII Compatible Encoding (ACE) representation. Here is one example to convert Unicode to ASCII and ASCII values to Unicode.

package com.pretech;
import java.net.IDN;
public class IDNExample {
	public static void main(String[] args) {
	        
	        String toAscciString = IDN.toASCII("http://ko.wikipedia.org/wiki/위키백과:대문");
	        System.out.println("Unicode to ASCII     " +toAscciString);
	        
	        String toUniCodeString = IDN.toUnicode(toAscciString);
	        System.out.println("ASCII  to unicode "+toUniCodeString);
	}
}

Output



Unicode to ASCII     http://ko.wikipedia.xn--org/wiki/:-4r01bby6brgzr7ct12dog6a
ASCII  to unicode http://ko.wikipedia.org/wiki/위키백과:대문

0 comments: