String (String varName, String input) { StringBuilder result = new StringBuilder(varName + " =\n\""); int curLineLength = 0; for (int i = 0; i < input.length(); i++) { char ch = input.charAt(i); String charRepresentation; if (ch == '"' || ch == '\\') { charRepresentation = "\\" + ch; } else if (ch < 127) { charRepresentation = Character.toString(ch); } else { charRepresentation = String.format("\\u%04X", (int)ch); } result.append(charRepresentation); curLineLength += charRepresentation.length(); if (curLineLength > LINE_LENGTH && i < input.length() - 1) { curLineLength = 0; result.append("\" +\n\""); } } return result.append("\";").toString(); }