java.lang.StringBuffer.replace()方法的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(8.4k)|赞(0)|评价(0)|浏览(213)

本文整理了Java中java.lang.StringBuffer.replace()方法的一些代码示例,展示了StringBuffer.replace()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。StringBuffer.replace()方法的具体详情如下:
包路径:java.lang.StringBuffer
类名称:StringBuffer
方法名:replace

StringBuffer.replace介绍

暂无

代码示例

代码示例来源:origin: Sable/soot

protected static String htmlify(String s) {
 StringBuffer b = new StringBuffer(s);
 for (int i = 0; i < b.length(); i++) {
  if (b.charAt(i) == '<') {
   b.replace(i, i + 1, "&lt;");
  }
  if (b.charAt(i) == '>') {
   b.replace(i, i + 1, "&gt;");
  }
 }
 return b.toString();
}

代码示例来源:origin: org.apache.ant/ant

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();
}

代码示例来源:origin: apache/geode

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();
}

代码示例来源:origin: org.apache.poi/poi

/** {@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);
  }
}

代码示例来源:origin: Sable/soot

/** 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();
}

代码示例来源:origin: robovm/robovm

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);
  }
}

代码示例来源:origin: iMeiji/Toutiao

/**
   * 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;
  }
}

代码示例来源:origin: pentaho/pentaho-kettle

/**
 * 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--;
 }
}

代码示例来源:origin: blynkkk/blynk-server

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();
}

代码示例来源:origin: plantuml/plantuml

public void writeStringTo(Cell cell, String str){
  if(isOutOfBounds(cell)) return;
  rows.get(cell.y).replace(cell.x, cell.x + str.length(), str);
}

代码示例来源:origin: org.codehaus.groovy/groovy

/**
 * 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());
}

代码示例来源:origin: org.codehaus.groovy/groovy

/**
 * 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());
}

代码示例来源:origin: org.apache.ant/ant

/**
   * 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;
  }
}

代码示例来源:origin: apache/geode

@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();
}

代码示例来源:origin: org.netbeans.api/org-openide-util

/**
* 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();
}

代码示例来源:origin: spring-projects/spring-data-mongodb

buffer.replace(quotationMarkIndex, quotationMarkIndex + 1, "\"");

代码示例来源:origin: org.apache.poi/poi

/**
 * 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();
}

代码示例来源:origin: org.apache.commons/commons-lang3

/**
 * 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;
}

代码示例来源:origin: commons-lang/commons-lang

/**
 * 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;
}

代码示例来源:origin: thinkaurelius/titan

qB.replace(startPos,endPos,replacement);
pos = startPos+replacement.length();
replacements++;

相关文章