Java Native to ASCII native2ascii(String code)

Here you can find the source of native2ascii(String code)

Description

nativeascii

License

Apache License

Declaration

public static String native2ascii(String code) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

public class Main {
    public static String native2ascii(String code) {
        char[] chars = code.toCharArray();
        int charValue = 0;
        String result = "";
        for (int i = 0; i < chars.length; i++) {
            charValue = (int) code.charAt(i);
            if (charValue <= 256) {
                // result += "& "+Integer.toHexString(charValue)+";";
                result += "\\" + Integer.toHexString(charValue);
            } else {
                // result += "&#x"+Integer.toHexString(charValue)+";";
                result += "\\u" + Integer.toHexString(charValue);
            }//from   w  w w  . j  a va2 s . c om
        }
        return result;
    }
}

Related

  1. native2ascii(String line)
  2. native2Ascii(String s)
  3. native2AscII(String str)
  4. nativeToAscii(String input)