List of usage examples for java.lang String replace
public String replace(CharSequence target, CharSequence replacement)
From source file:com.sds.acube.ndisc.mts.xserver.util.XNDiscCipher.java
/** * ? ? //from www.j av a 2 s .com * * @param string ? * @return ? ? ? ? ? */ private static String replaceChar(String string) { string = string.replace('/', '_'); string = string.replace('\\', '_'); return string; }
From source file:net.lordsofcode.zephyrus.utils.Lang.java
/** * Sends an error message to the specified CommandSender * // w w w . ja v a 2 s . com * @param key * The key to get * @param sender * The CommandSender to send the message to */ public static void errMsg(String key, CommandSender sender) { String txt = get(key); sender.sendMessage(ChatColor.DARK_RED + txt.replace("$", ChatColor.COLOR_CHAR + "")); }
From source file:Main.java
/** * Concatenates the two given path segments and returns a valid path, i.e. the method takes care that there is only * one path seperator between the path segments, and converts ':' to '_' in the appendix * * @param path The path./*from www . j av a2 s . co m*/ * @param appendix The path to append. * @return The concatenated path. */ public static String concatenatePath(final String path, final String appendix) { String result = path; String append = appendix.replaceAll(":", "_"); result = result.replace("\\", "/"); append = append.replace("\\", "/"); result += result.endsWith("/") ? append.startsWith("/") ? append.substring(1) : append : append.startsWith("/") ? append : '/' + append; return result; }
From source file:Main.java
/** * Return ARGB values in int array//from w w w . j a v a 2 s . co m * @param argb Color in HEX format (either with or without alpha, e.g. * #CCCCCC or #ffCCCCCC. * @return */ private static int[] getARGBComponents(String argb) { if (argb.startsWith("#")) { argb = argb.replace("#", ""); } int alpha = -1, red = -1, green = -1, blue = -1; if (argb.length() == 8) { alpha = Integer.parseInt(argb.substring(0, 2), 16); red = Integer.parseInt(argb.substring(2, 4), 16); green = Integer.parseInt(argb.substring(4, 6), 16); blue = Integer.parseInt(argb.substring(6, 8), 16); } else if (argb.length() == 6) { alpha = 255; red = Integer.parseInt(argb.substring(0, 2), 16); green = Integer.parseInt(argb.substring(2, 4), 16); blue = Integer.parseInt(argb.substring(4, 6), 16); } int[] components = { alpha, red, green, blue }; return components; }
From source file:Main.java
/** * Sanitize the given string to be {@link Uri} safe for building * {@link ContentProvider} paths.//from www . j av a 2 s. co m */ public static String sanitizeId(String input) { if (input == null) { return null; } return sSanitizePattern.matcher(input.replace("+", "plus").toLowerCase()).replaceAll(""); }
From source file:Main.java
private static String getHash(String s) { String next = s.substring(s.lastIndexOf("/"), s.length()); if (next.length() < 5) { return getHash(s.replace(next, "")); } else {//from w ww.j a v a 2 s .c o m return next; } }
From source file:com.redhat.lightblue.eval.EvalTestContext.java
public static QueryExpression queryExpressionFromJson(String s) throws Exception { return QueryExpression.fromJson(JsonUtils.json(s.replace('\'', '\"'))); }
From source file:blue.lapis.pore.vault.PoreVaultInjector.java
public static void inject() throws Exception { Plugin vault = Pore.getServer().getPluginManager().getPlugin("Vault"); if (vault == null) return;//w ww.jav a 2s .c o m ClassLoader loader = vault.getClass().getClassLoader(); LocalClassLoader injector = new LocalReflectClassLoader(loader); for (String addition : new String[] { "Hook", "Chat", "Economy", "Permissions" }) { String name = START + addition; URL url = Pore.class.getClassLoader().getResource(name.replace('.', '/') + ".class"); byte[] clazz = IOUtils.toByteArray(url); injector.defineClass(name, clazz); } Class.forName(HOOK, true, loader).getMethod("hook").invoke(null); }
From source file:Main.java
/** * Prepare and sanitize a string to be used as parameter for a command * @param s// w w w .ja va 2s.c o m * @return A string safe to use as parameter for a command */ public static String shellEscape(String s) { StringBuilder sb = new StringBuilder(s.length() + 200); sb.append("'"); sb.append(s.replace("'", "\\'").replace("\n", "\\\n")); sb.append("'"); return sb.toString(); }
From source file:Main.java
public static String handleExpiration(@NonNull String dateYear) { String expiryString = dateYear.replace(SLASH_SEPERATOR, ""); String text;//w w w. j a v a 2s .c o m if (expiryString.length() >= 2) { String mm = expiryString.substring(0, 2); String yy; text = mm; try { if (Integer.parseInt(mm) > 12) { mm = "12"; // Cannot be more than 12. } } catch (Exception e) { mm = "01"; } if (expiryString.length() >= 4) { yy = expiryString.substring(2, 4); try { Integer.parseInt(yy); } catch (Exception e) { Calendar calendar = Calendar.getInstance(); int year = calendar.get(Calendar.YEAR); yy = String.valueOf(year).substring(2); } text = mm + SLASH_SEPERATOR + yy; } else if (expiryString.length() > 2) { yy = expiryString.substring(2); text = mm + SLASH_SEPERATOR + yy; } } else { text = expiryString; } return text; }