Java tutorial
//package com.java2s; public class Main { public static String enquoteIdentifier(String s) { char[] raw = s.toCharArray(); StringBuilder stringBuilder = new StringBuilder(); for (char c : raw) { if (c < ' ' || c > '') { stringBuilder.append("\\u").append(String.format("%04x", c)); continue; } stringBuilder.append(c); } return stringBuilder.toString(); } }