List of usage examples for java.lang StringBuffer substring
@Override public synchronized String substring(int start, int end)
From source file:Main.java
/** Looks in findin for all occurrences of find and replaces them with replacewith * @param findin The string to find occurrences in * @param find The string to find/*from w ww . j a v a2 s . c o m*/ * @param replacewith The string to replace found occurrences with * @return A string with all occurrences of find replaced. */ public static String replace(String findin, String find, String replacewith) { StringBuffer sb = new StringBuffer(findin); int i = 0; try { while (i <= sb.length() - find.length()) { if (sb.substring(i, i + find.length()).equalsIgnoreCase(find)) { sb.replace(i, i + find.length(), replacewith); } i++; } } catch (StringIndexOutOfBoundsException e) { // We hit the end of the string - do nothing and carry on } return sb.toString(); }
From source file:org.kuali.rice.devtools.generators.dd.MaintDocDDCreator.java
public static String camelCaseToHelpParm(String className) { StringBuffer newName = new StringBuffer(className); // lower case the 1st letter newName.replace(0, 1, newName.substring(0, 1).toLowerCase()); // loop through, inserting spaces when cap for (int i = 0; i < newName.length(); i++) { if (Character.isUpperCase(newName.charAt(i))) { newName.insert(i, '_'); i++;/*from ww w . j av a 2 s.com*/ } } return newName.toString().toUpperCase().trim(); }
From source file:Main.java
public static boolean isValidExp(String exp, String[] columnNames) { StringBuffer sb = new StringBuffer(); for (int i = 0; i < columnNames.length; i++) { sb.append(columnNames[i] + "|"); }//from w w w .j av a2 s .c om String columnRegExp = "(" + sb.substring(0, sb.length() - 1) + ")"; columnRegExp = columnRegExp.replaceAll(reg3, "Z"); columnRegExp = columnRegExp.replaceAll(reg4, "Z"); String aggregateRegExp = reg1 + columnRegExp + reg2; exp = exp.replaceAll(reg3, "Z"); exp = exp.replaceAll(reg4, "Z"); Pattern p = Pattern.compile(aggregateRegExp); Matcher m = p.matcher(exp); boolean agg = m.matches(); p = Pattern.compile(columnRegExp); m = p.matcher(exp); return agg || m.matches(); }
From source file:Main.java
private static String toStringByArray(Object[] value) { StringBuffer sb = new StringBuffer(100); String type = value[0].getClass().getName(); sb.append("{").append(type).append("@"); for (int i = 0; i < value.length; i++) { sb.append(esc(value[i].toString())).append(","); }//from w w w . j a v a 2 s . co m return sb.substring(0, sb.length() - 1) + "}"; }
From source file:Main.java
/** * Transforms a collection of strings into a comma delimited string, where * each component get single-quoted./* w w w . ja v a 2 s . c o m*/ * * @param elements the collection of Integers * @return a comma delimited String. */ public static String getQuotedCommaDelimitedString(Collection<String> elements) { if (elements != null && elements.size() > 0) { final StringBuffer buffer = new StringBuffer(); for (String element : elements) { buffer.append("'").append(element.toString()).append("', "); } return buffer.substring(0, buffer.length() - ", ".length()); } return null; }
From source file:org.eclim.util.StringUtils.java
/** * Replaces placeholders of the form ${key} in the supplied string using * key / value pairs from the Map provided. * * @param string the String to evaluate. * @param values the values to use in the string. * @return The evaluation result.// w w w.ja va2s .c o m */ @SuppressWarnings("rawtypes") public static String replacePlaceholders(String string, Map values) { if (string == null || values == null) { return string; } StringBuffer buffer = new StringBuffer(string); int start = buffer.indexOf(PLACEHOLDER_PREFIX); int end = buffer.indexOf(PLACEHOLDER_SUFFIX); while (start != -1 && end != -1) { String placeholder = buffer.substring(start + PLACEHOLDER_PREFIX.length(), end); Object value = values.get(placeholder); if (value != null) { buffer.replace(start, end + 1, value.toString()); } start = buffer.indexOf(PLACEHOLDER_PREFIX, start + 1); end = buffer.indexOf(PLACEHOLDER_SUFFIX, start + 1); } return buffer.toString(); }
From source file:org.javlo.external.agitos.dkim.DKIMUtil.java
protected static String concatArray(ArrayList l, String separator) { StringBuffer buf = new StringBuffer(); Iterator iter = l.iterator(); while (iter.hasNext()) { buf.append(iter.next()).append(separator); }/*from w w w .ja v a2 s .c o m*/ return buf.substring(0, buf.length() - separator.length()); }
From source file:testutils.Utils.java
private static String toString(File[] listFiles) { StringBuffer buffer = new StringBuffer(); for (File file : listFiles) { buffer.append("\n + "); buffer.append(file.getAbsolutePath()); }/*from w ww. j a va 2 s . c o m*/ if (buffer.length() > 0) { return buffer.substring(0, buffer.length()); } else { return "none"; } }
From source file:info.globalbus.dkim.DKIMUtil.java
protected static String concatArray(ArrayList<String> l, String separator) { StringBuffer buf = new StringBuffer(); Iterator<String> iter = l.iterator(); while (iter.hasNext()) { buf.append(iter.next()).append(separator); }/*from ww w . ja va 2s . c o m*/ return buf.substring(0, buf.length() - separator.length()); }
From source file:org.exoplatform.portal.webui.application.GadgetUtil.java
static private String getLocalHostName() { PortalRequestContext pContext = Util.getPortalRequestContext(); StringBuffer requestUrl = pContext.getRequest().getRequestURL(); int index = requestUrl.indexOf(pContext.getRequestContextPath()); return requestUrl.substring(0, index); }