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

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

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

StringBuffer.charAt介绍

暂无

代码示例

代码示例来源:origin: ctripcorp/apollo

/**
  * filter out the first comment line
  * @param stringBuffer the string buffer
  * @return true if filtered successfully, false otherwise
  */
 static boolean filterPropertiesComment(StringBuffer stringBuffer) {
  //check whether has comment in the first line
  if (stringBuffer.charAt(0) != '#') {
   return false;
  }
  int commentLineIndex = stringBuffer.indexOf("\n");
  if (commentLineIndex == -1) {
   return false;
  }
  stringBuffer.delete(0, commentLineIndex + 1);
  return true;
 }
}

代码示例来源:origin: alibaba/arthas

public static void print(int number, List<Integer> primeFactors) {
  StringBuffer sb = new StringBuffer(number + "=");
  for (int factor : primeFactors) {
    sb.append(factor).append('*');
  }
  if (sb.charAt(sb.length() - 1) == '*') {
    sb.deleteCharAt(sb.length() - 1);
  }
  System.out.println(sb);
}

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

private boolean isPreviousChar(StringBuffer string, int index, char c) {
  boolean matches = false;
  if( index > 0 &&
    index < string.length() ) {
    matches = string.charAt(index - 1) == c;
  }
  return matches;
}

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

private boolean isNextChar(StringBuffer string, int index, char c) {
  boolean matches = false;
  if( index >= 0 &&
    index < string.length() - 1 ) {
    matches = string.charAt(index + 1) == c;
  }
  return matches;
}

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

/**
 * escape any occurrence of "/", "." and "\"
 */
private static String escape(String s) {
  StringBuffer sb = new StringBuffer(s);
  for (int i = 0; i < sb.length(); i++) {
    if (sb.charAt(i) == '/' || sb.charAt(i) == '\\' || sb.charAt(i) == '.') {
      sb.insert(i, '\\');
      i++;
    }
  }
  return sb.toString();
}

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

/**
 * Removes a backslash from every pair of backslashes. 
 */
private static String unescape(String s) {
  StringBuffer buf = new StringBuffer(s);
  for (int i = 0; i < buf.length() - 1; i++) {
    char c1 = buf.charAt(i);
    char c2 = buf.charAt(i + 1);
    if (c1 == '\\' && c2 == '\\') {
      buf.deleteCharAt(i);
    }
  }
  return buf.toString();
}

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

/**
 * Removes a backslash from every pair of backslashes. 
 */
private static String unescape(String s) {
  StringBuffer buf = new StringBuffer(s);
  for (int i = 0; i < buf.length() - 1; i++) {
    char c1 = buf.charAt(i);
    char c2 = buf.charAt(i + 1);
    if (c1 == '\\' && c2 == '\\') {
      buf.deleteCharAt(i);
    }
  }
  return buf.toString();
}

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

/**
 * Inserts a backslash before every comma and backslash. 
 */
private static String escape(String s) {
  StringBuffer buf = new StringBuffer(s);
  for (int i = 0; i < buf.length(); i++) {
    char c = buf.charAt(i);
    if (c == ',' || c == '\\') {
      buf.insert(i, '\\');
      i++;
    }
  }
  return buf.toString();
}

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

/**
 * <p>Remove the last field separator from the buffer.</p>
 *
 * @param buffer  the <code>StringBuffer</code> to populate
 * @since 2.0
 */
protected void removeLastFieldSeparator(final StringBuffer buffer) {
  final int len = buffer.length();
  final int sepLen = fieldSeparator.length();
  if (len > 0 && sepLen > 0 && len >= sepLen) {
    boolean match = true;
    for (int i = 0; i < sepLen; i++) {
      if (buffer.charAt(len - 1 - i) != fieldSeparator.charAt(sepLen - 1 - i)) {
        match = false;
        break;
      }
    }
    if (match) {
      buffer.setLength(len - sepLen);
    }
  }
}

代码示例来源: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: pentaho/pentaho-kettle

public String stripCR( StringBuffer sbsql ) {
 // DB2 Can't handle \n in SQL Statements...
 if ( !supportsNewLinesInSQL() ) {
  // Remove CR's
  for ( int i = sbsql.length() - 1; i >= 0; i-- ) {
   if ( sbsql.charAt( i ) == '\n' || sbsql.charAt( i ) == '\r' ) {
    sbsql.setCharAt( i, ' ' );
   }
  }
 }
 return sbsql.toString();
}

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

/**
 * <p>Remove the last field separator from the buffer.</p>
 *
 * @param buffer  the <code>StringBuffer</code> to populate
 * @since 2.0
 */
protected void removeLastFieldSeparator(StringBuffer buffer) {
  int len = buffer.length();
  int sepLen = fieldSeparator.length();
  if (len > 0 && sepLen > 0 && len >= sepLen) {
    boolean match = true;
    for (int i = 0; i < sepLen; i++) {
      if (buffer.charAt(len - 1 - i) != fieldSeparator.charAt(sepLen - 1 - i)) {
        match = false;
        break;
      }
    }
    if (match) {
      buffer.setLength(len - sepLen);
    }
  }
}

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

/**
 * Inserts a backslash before every comma and backslash. 
 */
private static String escape(String s) {
  StringBuffer buf = new StringBuffer(s);
  for (int i = 0; i < buf.length(); i++) {
    char c = buf.charAt(i);
    if (c == ',' || c == '\\') {
      buf.insert(i, '\\');
      i++;
    }
  }
  return buf.toString();
}

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

/**
  * Gets HEADER portion of packet.
  * @param timeStamp number of milliseconds after the standard base time.
  * @return HEADER portion of packet, will be zero-length string if header is false.
  * @since 1.2.15
  */
private String getPacketHeader(final long timeStamp) {
  if (header) {
   StringBuffer buf = new StringBuffer(dateFormat.format(new Date(timeStamp)));
   //  RFC 3164 says leading space, not leading zero on days 1-9
   if (buf.charAt(4) == '0') {
    buf.setCharAt(4, ' ');
   }
   buf.append(getLocalHostname());
   buf.append(' ');
   return buf.toString();
  }
  return "";
}

代码示例来源:origin: internetarchive/heritrix3

/**
  Tests if this string ends with a character.
  @param ch the character to test for
  @return true if and only if this string ends with ch
*/
boolean endsWith(char ch) {
  assert checkInvariants();
  int len = string.length();
  return (0 != len) && (string.charAt(len - 1) == ch);
}

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

public static String getPrintableText(List<Candidate> candidates) {
  StringBuffer sb = new StringBuffer();
  sb.append("[");
  for (Candidate candidate : candidates) {
    IRealization r = candidate.realization;
    sb.append(r.getCanonicalName());
    sb.append(",");
  }
  if (sb.charAt(sb.length() - 1) != '[')
    sb.deleteCharAt(sb.length() - 1);
  sb.append("]");
  return sb.toString();
}

代码示例来源:origin: JetBrains/ideavim

private boolean prog_magic_wrong() {
 if ((reg_match == null ? reg_mmatch.regprog.program : reg_match.regprog.program).charAt(0) != REGMAGIC) {
  VimPlugin.showMessage(MessageHelper.message(Msg.e_re_corr));
  return true;
 }
 return false;
}

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

public char get(int x, int y){
  if(x > getWidth() - 1
    || y > getHeight() - 1
    || x < 0
    || y < 0) return 0;
  return rows.get(y).charAt(x);
}

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

public char get(Cell cell){
  if(cell.x > getWidth() - 1
    || cell.y > getHeight() - 1
    || cell.x < 0
    || cell.y < 0) return 0;
  return rows.get(cell.y).charAt(cell.x);
}

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

private static boolean shouldAppendSpace(StringBuffer text, char firstCharToAppend) {
  final boolean result;
  if (text.length() == 0) {
    result = false;
  }
  else {
    final char last = text.charAt(text.length() - 1);
    result = (last == ':' || firstCharToAppend == '@' || Character.isAlphabetic(last)
        || Character.isAlphabetic(firstCharToAppend)) && !Character.isWhitespace(last);
  }
  return result;
}

相关文章