Unicode to ASCII - Java java.lang

Java examples for java.lang:String Unicode

Description

Unicode to ASCII

Demo Code


//package com.java2s;

public class Main {
    public static void main(String[] argv) throws Exception {
        String unicode = "java2s.com";
        System.out.println(Unicode2ASCII(unicode));
    }/*from  w w w . j a v  a 2 s .c  o m*/

    public static String Unicode2ASCII(String unicode) {
        StringBuffer ascii = new StringBuffer(unicode);
        int code;
        for (int i = 0; i < unicode.length(); i++) {
            code = (int) unicode.charAt(i);
            if ((0xE01 <= code) && (code <= 0xE5B))
                ascii.setCharAt(i, (char) (code - 0xD60));
        }
        return ascii.toString();
    }
}

Related Tutorials