List of usage examples for java.lang StringBuilder replace
@Override public StringBuilder replace(int start, int end, String str)
From source file:org.apache.lucene.search.SearchUtil.java
public static String removeTitle(String contents, String title) { if (contents.indexOf("$TITLE_START$") != -1 && contents.indexOf("$TITLE_END$") != -1) { StringBuilder sb = new StringBuilder(contents); int start = sb.indexOf("$TITLE_START$"); int end = sb.indexOf("$TITLE_END$"); String tmp = sb.replace(start, end + "$TITLE_END$".length(), "").toString(); return StringUtils.removeStart(tmp, title); } else {//from w ww .j a v a2 s. c o m return contents; } }
From source file:com.chintans.venturebox.util.Utils.java
public static String getReadableVersion(String version) { try {/*from w ww. ja v a 2s . c om*/ String number = version.substring(version.indexOf("-") + 1, version.lastIndexOf("-")); String date = version.substring(version.lastIndexOf("-") + 1, version.endsWith(".zip") ? version.lastIndexOf(".") : version.length()); SimpleDateFormat curFormater = new SimpleDateFormat("yyyyMMdd"); Date dateObj = null; try { dateObj = curFormater.parse(date); } catch (ParseException e) { // ignore } SimpleDateFormat postFormater = new SimpleDateFormat("MMMM dd, yyyy"); if (dateObj == null) { return number; } String newDateStr = postFormater.format(dateObj); StringBuilder b = new StringBuilder(newDateStr); int i = 0; do { b.replace(i, i + 1, b.substring(i, i + 1).toUpperCase()); i = b.indexOf(" ", i) + 1; } while (i > 0 && i < b.length()); return number + " - " + b.toString(); } catch (Exception ex) { // unknown version format return version; } }
From source file:org.apache.hadoop.hive.common.jsonexplain.tez.TezJsonParser.java
/** * @param indentFlag//from w w w .j a v a 2 s . com * @param tail * help to generate correct indent with a specific tail * @return */ public static String prefixString(List<Boolean> indentFlag, String tail) { StringBuilder sb = new StringBuilder(); for (int index = 0; index < indentFlag.size(); index++) { if (indentFlag.get(index)) sb.append("| "); else sb.append(" "); } int len = sb.length(); return sb.replace(len - tail.length(), len, tail).toString(); }
From source file:Main.java
private static StringBuilder replaceString(StringBuilder text, String search, String replace) { int fromIndex = 0; int start = text.indexOf(search, fromIndex); if (start == -1) { return text; }//from ww w . ja v a 2s. c om if (replace.length() > 0) { int end = 0; int endAdjust = (search.length() - replace.length()); do { end = (start + replace.length()) + endAdjust; text.replace(start, end, replace); fromIndex = end; } while ((start = text.indexOf(search, fromIndex)) != -1); } else { do { text.delete(start, search.length()); fromIndex = start + replace.length(); } while ((start = text.indexOf(search, fromIndex)) != -1); } return text; }
From source file:com.cloudera.impala.common.FileSystemUtil.java
/** * Builds a new file name based on a base file name. This is done by inserting * the given appendStr into the base file name, preserving the file extension (if * one exists).//from w w w .j ava 2s . c om * For example, this could be passed a UUID string to uniquify files: * file1.snap -> file1_<uuid>.snap * file1 -> file1_<uuid> */ private static String appendToBaseFileName(String baseFileName, String appendStr) { StringBuilder sb = new StringBuilder(baseFileName); // Insert the string to append, preserving the file extension. int extensionIdx = baseFileName.lastIndexOf('.'); if (extensionIdx != -1) { sb.replace(extensionIdx, extensionIdx + 1, "_" + appendStr + "."); } else { sb.append("_" + appendStr); } return sb.toString(); }
From source file:oscar.eform.data.DatabaseAP.java
public static String parserReplace(String name, String var, String str) { //replaces <$name$> with var in str StringBuilder strb = new StringBuilder(str); int tagstart = -2; int tagend;/* w w w.j a va 2 s. c o m*/ while ((tagstart = strb.indexOf("${", tagstart + 2)) >= 0) { tagend = strb.indexOf("}", tagstart); if (strb.substring(tagstart + 2, tagend).equals(name)) { strb.replace(tagstart, tagend + 1, var == null ? "" : var); } } return strb.toString(); }
From source file:com.melani.utils.ProjectHelpers.java
public static String parsearCaracteresEspecialesXML(String xmlNota) { String xml = "No paso Nada"; StringBuilder sb = null; try {// w ww .j a v a 2s. c o m sb = new StringBuilder(); sb.append(xmlNota); xml = StringEscapeUtils .escapeXml10(xmlNota.substring(xmlNota.indexOf("es>") + 3, xmlNota.indexOf("</ob"))); sb.replace(sb.indexOf("es>") + 3, sb.indexOf("</ob"), xml); } catch (Exception e) { xml = "Error"; logger.error("Error en metodo parsearCaracteresEspecialesXML " + e.getMessage()); } finally { return sb.toString(); } }
From source file:org.apache.lucene.search.SearchUtil.java
public static String removeJspTags(String contents) { StringBuilder sb = new StringBuilder(contents); while (true) { if (sb.indexOf("<%") != -1 && sb.indexOf("%>") != -1) { int start = sb.indexOf("<%"); int end = sb.indexOf("%>"); sb.replace(start, end + 2, ""); } else {//from ww w . j a va2 s . com break; } } return sb.toString(); }
From source file:Main.java
/** * Escapes a string builder so that it is valid XML. * //from w w w . ja v a 2 s . c o m * @param sb * The string builder to escape. */ public static void escapeXML(StringBuilder sb) { // double quote -- quot // ampersand -- amp // less than -- lt // greater than -- gt // apostrophe -- apos for (int i = 0; i < sb.length();) { int codePoint = Character.codePointAt(sb, i); int length = Character.charCount(codePoint); if (codePoint == '<') { sb.replace(i, i + length, LT); i += LT.length(); } else if (codePoint == '>') { sb.replace(i, i + length, GT); i += GT.length(); } else if (codePoint == '\"') { sb.replace(i, i + length, QUOT); i += QUOT.length(); } else if (codePoint == '&') { sb.replace(i, i + length, AMP); i += AMP.length(); } else if (codePoint == '\'') { sb.replace(i, i + length, APOS); i += APOS.length(); } else { i += length; } } }
From source file:de.zib.gndms.gndmc.test.gorfx.GORFXClientMain.java
public static void showList(String name, List<String> list) { StringBuilder sb = new StringBuilder(); sb.append(name).append(": "); if (list == null || list.size() == 0) { sb.append("NIL\n"); return;/* w ww .j a va 2 s . co m*/ } for (String s : list) { sb.append(s); sb.append(","); } sb.replace(sb.length() - 1, sb.length() - 1, ""); System.out.println(sb.toString()); }