ascii to native - Java java.lang

Java examples for java.lang:String UTF

Description

ascii to native

Demo Code


//package com.java2s;

public class Main {
    public static String ascii2native(String asciicode) {
        String[] asciis = asciicode.split("\\\\u");
        String nativeValue = asciis[0];
        try {//from w  w  w .j a  v a 2  s  . co m
            for (int i = 1; i < asciis.length; i++) {
                String code = asciis[i];
                nativeValue += (char) Integer.parseInt(
                        code.substring(0, 4), 16);
                if (code.length() > 4) {
                    nativeValue += code.substring(4, code.length());
                }
            }
        } catch (NumberFormatException e) {
            return asciicode;
        }
        return nativeValue;
    }
}

Related Tutorials