private String condenseText(final String text) { if (text.length() <= MAX_REPORT_NESTED_TEXT) { return text; } final int ends = (MAX_REPORT_NESTED_TEXT - ELLIPSIS.length()) / 2; return new StringBuffer(text).replace(ends, text.length() - ends, ELLIPSIS).toString(); }
public static String rightJustify(long n) { // There's probably a better way to do this... String field = " "; String num = Long.toString(n); if (num.length() >= field.length()) return num; StringBuffer b = new StringBuffer(field); b.replace(b.length() - num.length(), b.length(), num); return b.toString(); }
/** {@inheritDoc} */ public void formatValue(StringBuffer toAppendTo, Object obj) { int start = toAppendTo.length(); String text = obj.toString(); if (obj instanceof Boolean) { text = text.toUpperCase(Locale.ROOT); } toAppendTo.append(desc); for (int textPo : textPos) { int pos = start + textPo; toAppendTo.replace(pos, pos + 1, text); } }
/** Replace all occurrences of a given substring in a given {@link String}. */ public static String replaceAll(String str_, String sub_, String newSub_) { if (str_.indexOf(sub_) == -1) { return str_; } int subLen = sub_.length(); int idx; StringBuffer result = new StringBuffer(str_); while ((idx = result.toString().indexOf(sub_)) >= 0) { result.replace(idx, idx + subLen, newSub_); } return result.toString(); }
public void replaceData(int offset, int count, String arg) throws DOMException { try { buffer.replace(offset, offset + count, arg); } catch (ArrayIndexOutOfBoundsException ex) { throw new DOMException(DOMException.INDEX_SIZE_ERR, null); } }
/** * Unicode编码转汉字 */ public static String UnicodeToChs(String s) { StringBuffer sb = new StringBuffer(s); int pos; while ((pos = sb.indexOf("\\u")) > -1) { String tmp = sb.substring(pos, pos + 6); sb.replace(pos, pos + 6, Character.toString((char) Integer.parseInt(tmp.substring(2), 16))); } s = sb.toString(); return s; } }
/** * Alternate faster version of string replace using a stringbuffer as input. * * @param str * The string where we want to replace in * @param code * The code to search for * @param repl * The replacement string for code */ public static void replaceBuffer( StringBuffer str, String code, String repl ) { int clength = code.length(); int i = str.length() - clength; while ( i >= 0 ) { String look = str.substring( i, i + clength ); if ( look.equalsIgnoreCase( code ) ) { // Look for a match! str.replace( i, i + clength, repl ); } i--; } }
private static String getPropertyAsString(Properties prop) { StringWriter writer = new StringWriter(); prop.list(new PrintWriter(writer)); return writer.getBuffer().replace(0, "-- listing properties --\n".length(), "").toString(); }
public void writeStringTo(Cell cell, String str){ if(isOutOfBounds(cell)) return; rows.get(cell.y).replace(cell.x, cell.x + str.length(), str); }
/** * Support the range subscript operator for StringBuffer. * * @param self a StringBuffer * @param range a Range * @param value the object that's toString() will be inserted * @since 1.0 */ public static void putAt(StringBuffer self, EmptyRange range, Object value) { RangeInfo info = subListBorders(self.length(), range); self.replace(info.from, info.to, value.toString()); }
/** * Support the range subscript operator for StringBuffer. Index values are * treated as characters within the buffer. * * @param self a StringBuffer * @param range a Range * @param value the object that's toString() will be inserted * @since 1.0 */ public static void putAt(StringBuffer self, IntRange range, Object value) { RangeInfo info = subListBorders(self.length(), range); self.replace(info.from, info.to, value.toString()); }
/** * Performs the replace operation. * @return The position of the last character that was inserted as * replacement. */ private int replace() { String t = getToken(); int found = inputBuffer.indexOf(t); int pos = -1; final int tokenLength = t.length(); final int replaceValueLength = replaceValue.length(); while (found >= 0) { inputBuffer.replace(found, found + tokenLength, replaceValue); pos = found + replaceValueLength; found = inputBuffer.indexOf(t, pos); ++replaceCount; } return pos; } }
@Override public String toString() { StringBuffer buffer = new StringBuffer(200); buffer.append("[Mail Host: "); buffer.append(getMailHost()); buffer.append("]"); buffer.append(" [Mail From: "); buffer.append(getMailFromAddress()); buffer.append("]"); buffer.append(" [Mail To: "); if (mailToAddresses.length > 0) { for (int i = 0; i < mailToAddresses.length; i++) { buffer.append(mailToAddresses[i]); buffer.append(", "); } buffer.replace(buffer.length() - 2, buffer.length(), ""); } else { buffer.append(" Undefined"); } buffer.append("]"); return buffer.toString(); }
/** * Parses the string. Does not yet handle recursion (where * the substituted strings contain {n} references.) * @return New format. */ public String parse(String source) { StringBuffer sbuf = new StringBuffer(source); Iterator key_it = argmap.keySet().iterator(); //skipped = new RangeList(); // What was this for?? //process(source, "\"", "\""); // NOI18N while (key_it.hasNext()) { String it_key = (String) key_it.next(); String it_obj = formatObject(argmap.get(it_key)); int it_idx = -1; do { it_idx = sbuf.toString().indexOf(it_obj, ++it_idx); if (it_idx >= 0 /* && !skipped.containsOffset(it_idx) */ ) { sbuf.replace(it_idx, it_idx + it_obj.length(), ldel + it_key + rdel); //skipped = new RangeList(); // What was this for?? //process(sbuf.toString(), "\"", "\""); // NOI18N } } while (it_idx != -1); } return sbuf.toString(); }
buffer.replace(quotationMarkIndex, quotationMarkIndex + 1, "\"");
/** * Creates a elapsed time formatter. * * @param pattern The pattern to parse. */ public CellElapsedFormatter(String pattern) { super(pattern); specs = new ArrayList<>(); StringBuffer desc = CellFormatPart.parseFormat(pattern, CellFormatType.ELAPSED, new ElapsedPartHandler()); ListIterator<TimeSpec> it = specs.listIterator(specs.size()); while (it.hasPrevious()) { TimeSpec spec = it.previous(); desc.replace(spec.pos, spec.pos + spec.len, "%0" + spec.len + "d"); if (spec.type != topmost.type) { spec.modBy = modFor(spec.type, spec.len); } } printfFmt = desc.toString(); }
/** * Replaces all the occurrences of variables within the given source buffer * with their matching values from the resolver. * The buffer is updated with the result. * <p> * Only the specified portion of the buffer will be processed. * The rest of the buffer is not processed, but it is not deleted. * * @param source the buffer to replace in, updated, null returns zero * @param offset the start offset within the array, must be valid * @param length the length within the buffer to be processed, must be valid * @return true if altered */ public boolean replaceIn(final StringBuffer source, final int offset, final int length) { if (source == null) { return false; } final StrBuilder buf = new StrBuilder(length).append(source, offset, length); if (substitute(buf, 0, length) == false) { return false; } source.replace(offset, offset + length, buf.toString()); return true; }
/** * Replaces all the occurrences of variables within the given source buffer * with their matching values from the resolver. * The buffer is updated with the result. * <p> * Only the specified portion of the buffer will be processed. * The rest of the buffer is not processed, but it is not deleted. * * @param source the buffer to replace in, updated, null returns zero * @param offset the start offset within the array, must be valid * @param length the length within the buffer to be processed, must be valid * @return true if altered */ public boolean replaceIn(StringBuffer source, int offset, int length) { if (source == null) { return false; } StrBuilder buf = new StrBuilder(length).append(source, offset, length); if (substitute(buf, 0, length) == false) { return false; } source.replace(offset, offset + length, buf.toString()); return true; }
qB.replace(startPos,endPos,replacement); pos = startPos+replacement.length(); replacements++;