List of usage examples for java.lang String replace
public String replace(CharSequence target, CharSequence replacement)
From source file:Main.java
public static String escapeURL(String link) { try {//from w w w .jav a 2s. c o m String path = link; path = java.net.URLEncoder.encode(path, "utf8"); path = path.replace("%3A", ":"); path = path.replace("%2F", "/"); path = path.replace("+", "%20"); path = path.replace("%23", "#"); path = path.replace("%3D", "="); return path; } catch (Exception e) { link = link.replaceAll("\\[", "%5B"); link = link.replaceAll("\\]", "%5D"); link = link.replaceAll("\\s", "%20"); } return link; }
From source file:com.difference.historybook.importer.crawler.Crawler.java
private static String encodeSpecialChars(String url) { String result = url.replace("{", "%7B").replace("}", "%7D").replace("#", "%23").replace("|", "%7C") .replace(" ", "%20"); return result; }
From source file:Main.java
@SuppressWarnings("rawtypes") public static String jsonEncode(Object result) { if (result instanceof JSONObject) { return ((JSONObject) result).toString(); } else if (result instanceof JSONArray) { return ((JSONArray) result).toString(); } else if (result instanceof Map) { return new JSONObject((Map) result).toString(); } else if (result instanceof List) { return new JSONArray((List) result).toString(); } else if (result instanceof Integer) { return ((Integer) result).toString(); } else if (result instanceof Double) { return ((Double) result).toString(); } else if (result instanceof Float) { return ((Float) result).toString(); } else if (result instanceof String) { String str = (String) result; return "\"" + str.replace("\"", "\\\"") + "\""; } else if (result instanceof Boolean) { if (((Boolean) result).booleanValue()) { return "true"; }//from w ww .j a va 2 s .co m return "false"; } else if (result == null) { return "null"; } return null; }
From source file:Main.java
public static List<String> getChildNode(String xmlString, String node) { List<String> list = new ArrayList<String>(); int start = 0, end = 0; do {/*from w w w . j a v a2 s . c om*/ start = xmlString.indexOf("<" + node + ">", start); end = xmlString.indexOf("</" + node + ">", end); if (start == -1 || end == -1) { break; } end += node.length() + 3; String subStr = xmlString.substring(start, end); start += 1; subStr = subStr.replace("<![CDATA[", "").replace("]]>", ""); list.add(subStr); } while (true); return list; }
From source file:Main.java
/** * sanitize the filename/*www .j ava2s . c om*/ * @param fileName * @return */ static String validateFileName(String fileName) { if (fileName == null) return null; fileName = fileName.replace('/', '_'); fileName = fileName.replace('<', '_'); fileName = fileName.replace('>', '_'); fileName = fileName.replace(':', '_'); fileName = fileName.replace('\'', '_'); fileName = fileName.replace('?', '_'); fileName = fileName.replace('"', '_'); fileName = fileName.replace('|', '_'); fileName = fileName.replace('(', '_'); fileName = fileName.replace(')', '_'); fileName = fileName.replace('[', '_'); fileName = fileName.replace(']', '_'); fileName = fileName.replaceAll("%", ""); return fileName; }
From source file:net.lordsofcode.zephyrus.utils.Lang.java
/** * Sends a message to the specified CommandSender * /*from ww w.j a v a 2 s . c o m*/ * @param key * The key to get * @param sender * The CommandSender to send the message to */ public static void msg(String key, CommandSender sender) { String txt = get(key); sender.sendMessage(txt.replace("$", ChatColor.COLOR_CHAR + "")); }
From source file:Main.java
private static String normaliseUnicode(String unicodeText, char[] mappings) { String result = unicodeText; for (int i = 0; i < mappings.length; i += 2) { result = result.replace(mappings[i], mappings[i + 1]); }/* w w w . j a va2 s .com*/ return result; }
From source file:com.synopsys.integration.util.EnumUtils.java
public static String prettyPrint(Enum<?> enumValue) { String name = enumValue.name(); String prettyName = WordUtils.capitalizeFully(name.replace("_", " ")); return prettyName; }
From source file:com.gargoylesoftware.js.CodeUpdater.java
private static void processFile(final File originalFile, final boolean isMain) throws IOException { String relativePath = originalFile.getPath().replace('\\', '/'); relativePath = "com/gargoylesoftware/js/" + relativePath.substring(relativePath.indexOf("/jdk/") + "/jdk/".length()); final String root = isMain ? "src/main/java/" : "src/test/java/"; final File localFile = new File(root + relativePath); if (!localFile.exists()) { System.out.println("File doesn't locally exist: " + relativePath); return;//from w w w. j a v a 2 s .c o m } final List<String> originalLines = FileUtils.readLines(originalFile); final List<String> localLines = FileUtils.readLines(localFile); while (!isCodeStart(originalLines.get(0))) { originalLines.remove(0); } for (int i = 0; i < localLines.size(); i++) { if (isCodeStart(localLines.get(i))) { while (i < localLines.size()) { localLines.remove(i); } break; } } for (int i = 0; i < originalLines.size(); i++) { String line = originalLines.get(i); line = line.replace("jdk.internal.org.objectweb.asm", "org.objectweb.asm"); line = line.replace("jdk.nashorn.internal", "com.gargoylesoftware.js.nashorn.internal"); line = line.replace("jdk/nashorn/internal", "com/gargoylesoftware/js/nashorn/internal"); line = line.replace("jdk/nashorn/javaadapters", "com/gargoylesoftware/js/nashorn/javaadapters"); line = line.replace("jdk.nashorn.api", "com.gargoylesoftware.js.nashorn.api"); line = line.replace("jdk.nashorn.tools", "com.gargoylesoftware.js.nashorn.tools"); line = line.replace("jdk.internal.dynalink", "com.gargoylesoftware.js.internal.dynalink"); line = line.replace(" @Constructor", " @com.gargoylesoftware.js.nashorn.internal.objects.annotations.Constructor"); line = line.replace(" @Property", " @com.gargoylesoftware.js.nashorn.internal.objects.annotations.Property"); originalLines.set(i, line); if (line.equals("@jdk.Exported")) { originalLines.remove(i--); } } localLines.addAll(originalLines); FileUtils.writeLines(localFile, localLines); }
From source file:dk.dma.navnet.client.AbstractClientConnectionTest.java
protected static String escape(String s) { return s.replace("\\", "\\\\").replace("\"", "\\\""); }