List of usage examples for java.lang String replace
public String replace(CharSequence target, CharSequence replacement)
From source file:Main.java
/** * Parse a URL query and fragment parameters into a key-value bundle. * * @param url the URL to parse/*from www . jav a2 s . co m*/ * @return a dictionary bundle of keys and values */ @Deprecated public static Bundle parseUrl(String url) { // hack to prevent MalformedURLException url = url.replace("fbconnect", "http"); try { URL u = new URL(url); Bundle b = decodeUrl(u.getQuery()); b.putAll(decodeUrl(u.getRef())); return b; } catch (MalformedURLException e) { return new Bundle(); } }
From source file:com.redhat.lightblue.eval.EvalTestContext.java
public static Projection projectionFromJson(String s) throws Exception { return Projection.fromJson(JsonUtils.json(s.replace('\'', '\"'))); }
From source file:Main.java
/** * <p>Return subMap from target Map where the key start with appointing keyPrefix, subMap's remove keyPrefix</p> * <p>subMap([key1:value1,key21:value21,key22:value22], new HashMap(), key2) return [1:value21,2:value22]</p> * @param sourceMap//from w w w. ja v a 2 s . com * @param targetMap * @param keyPrefix * @return */ public static <E extends Object> Map<String, E> subMap(Map<String, E> sourceMap, Map<String, E> targetMap, String keyPrefix) { Set<Map.Entry<String, E>> entrys = sourceMap.entrySet(); for (Map.Entry<String, E> entry : entrys) { String key = entry.getKey(); if (key != null && key.startsWith(keyPrefix)) { targetMap.put(key.replace(keyPrefix, ""), entry.getValue()); } } return targetMap; }
From source file:Main.java
public static String handleCardNumber(String inputCardNumber, String seperator) { String formattingText = inputCardNumber.replace(seperator, ""); String text;/*from w w w.j ava 2 s . c o m*/ if (formattingText.length() >= 4) { text = formattingText.substring(0, 4); if (formattingText.length() >= 8) { text += seperator + formattingText.substring(4, 8); } else if (formattingText.length() > 4) { text += seperator + formattingText.substring(4); } if (formattingText.length() >= 12) { text += seperator + formattingText.substring(8, 12); } else if (formattingText.length() > 8) { text += seperator + formattingText.substring(8); } if (formattingText.length() >= 16) { text += seperator + formattingText.substring(12); } else if (formattingText.length() > 12) { text += seperator + formattingText.substring(12); } return text; } else { text = formattingText.trim(); } return text; }
From source file:de.vanita5.twittnuker.util.HtmlEscapeHelper.java
public static String toPlainText(final String string) { if (string == null) return null; return unescape(string.replace("<br/>", "\n").replaceAll("<!--.*?-->|<[^>]+>", "")); }
From source file:Main.java
public static String ensureUnique(Set<String> nameSet, String name) { String paramName = name; if (null != paramName && -1 != paramName.indexOf(".")) { paramName = paramName.replace('.', '_'); }/*from w w w . j a v a2 s .com*/ if (nameSet.contains(paramName)) { int index = 1; String tempVar = null; while (true) { tempVar = paramName + "_" + index; if (!nameSet.contains(tempVar)) { break; } index++; } paramName = tempVar; } return paramName; }
From source file:com.arrow.acs.ManifestUtils.java
public static Manifest readManifest(Class<?> clazz) { String method = "readManifest"; String jarFile = null;// w w w . j ava 2 s . com String path = clazz.getProtectionDomain().getCodeSource().getLocation().toString(); for (String token : path.split("/")) { token = token.replace("!", "").toLowerCase().trim(); if (token.endsWith(".jar")) { jarFile = token; break; } } LOGGER.logInfo(method, "className: %s, path: %s, jarFile: %s", clazz.getName(), path, jarFile); InputStream is = null; try { if (!StringUtils.isEmpty(jarFile)) { Enumeration<URL> enumeration = Thread.currentThread().getContextClassLoader() .getResources(JarFile.MANIFEST_NAME); while (enumeration.hasMoreElements()) { URL url = enumeration.nextElement(); for (String token : url.toString().split("/")) { token = token.replace("!", "").toLowerCase(); if (token.equals(jarFile)) { LOGGER.logInfo(method, "loading manifest from: %s", url.toString()); return new Manifest(is = url.openStream()); } } } } else { URL url = new URL(path + "/META-INF/MANIFEST.MF"); LOGGER.logInfo(method, "loading manifest from: %s", url.toString()); return new Manifest(is = url.openStream()); } } catch (IOException e) { } finally { IOUtils.closeQuietly(is); } LOGGER.logError(method, "manifest file not found for: %s", clazz.getName()); return null; }
From source file:org.ambraproject.wombat.service.remote.ApiAddress.java
private static String escapeDoi(String doi) { return doi.replace("+", "+-").replace("/", "++"); }
From source file:com.kylinolap.job.tools.OptionsHelper.java
public static String convertToFileURL(String path) { if (File.separatorChar != '/') { path = path.replace(File.separatorChar, '/'); }//from w w w . j a v a2 s. c o m return path; }
From source file:com.lucas.analytics.controller.ml.SearchController.java
public static Search getSearch(String query) throws IOException { ObjectMapper mapper = new ObjectMapper(); String noWhitespace = query.replace(" ", "+"); String targetUrl = baseUrl + "?q=" + StringEscapeUtils.escapeHtml4(noWhitespace) + "&limit=10"; System.out.println("targetUrl: " + targetUrl); return mapper.readValue(Request.Get(targetUrl).execute().returnContent().asString(), Search.class); }