java.lang.StringBuilder.lastIndexOf()方法的使用及代码示例

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

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

StringBuilder.lastIndexOf介绍

暂无

代码示例

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

private int find_extension()
{
  int lastSlashIndex;

  final StringBuilder str = mString;
  // only look at the filename
  lastSlashIndex = str.lastIndexOf(File.pathSeparator);
  if (lastSlashIndex == -1) {
   lastSlashIndex = 0;
  } else {
   lastSlashIndex++;
  }
  // find the last dot
  return str.lastIndexOf(".", lastSlashIndex);
}

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

private static void appendSeparatorToScriptIfNecessary(StringBuilder scriptBuilder, @Nullable String separator) {
  if (separator == null) {
    return;
  }
  String trimmed = separator.trim();
  if (trimmed.length() == separator.length()) {
    return;
  }
  // separator ends in whitespace, so we might want to see if the script is trying
  // to end the same way
  if (scriptBuilder.lastIndexOf(trimmed) == scriptBuilder.length() - trimmed.length()) {
    scriptBuilder.append(separator.substring(trimmed.length()));
  }
}

代码示例来源:origin: lets-blade/blade

private static StringBuilder clearLastComma(StringBuilder buff) {
  int lastComma = buff.lastIndexOf(", ");
  // No comma found, take everything
  if (-1 != lastComma)
    buff.delete(lastComma, buff.length());
  return buff;
}

代码示例来源:origin: lets-blade/blade

private static StringBuilder clearLastComma(StringBuilder buff) {
  int lastComma = buff.lastIndexOf(", ");
  // No comma found, take everything
  if (-1 != lastComma)
    buff.delete(lastComma, buff.length());
  return buff;
}

代码示例来源:origin: google/j2objc

private static String join(StringBuilder out, Object[] linesToBreak) {
    for (Object line : linesToBreak) {
      out.append(line.toString()).append("\n");
    }
    int lastBreak = out.lastIndexOf("\n");
    return out.replace(lastBreak, lastBreak+1, "").toString();
  }
}

代码示例来源:origin: google/error-prone

private static String replaceLast(String text, String pattern, String replacement) {
 StringBuilder builder = new StringBuilder(text);
 int lastIndexOf = builder.lastIndexOf(pattern);
 return builder.replace(lastIndexOf, lastIndexOf + pattern.length(), replacement).toString();
}

代码示例来源:origin: google/error-prone

private String replaceLast(String text, String pattern, String replacement) {
  StringBuilder builder = new StringBuilder(text);
  int lastIndexOf = builder.lastIndexOf(pattern);
  return builder.replace(lastIndexOf, lastIndexOf + pattern.length(), replacement).toString();
 }
},

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

static void replaceVariable(StringBuilder sb, String key, String value) {
    // infinite loop avoidance
    if (key.equals(value)) {
      return;
    }

    // replace with minimum char movement
    int idx = sb.lastIndexOf(key);
    while (idx >= 0) {
      sb.replace(idx, idx + key.length(), value);
      idx = sb.lastIndexOf(key, idx);
    }
  }
}

代码示例来源:origin: networknt/light-4j

private void removeLastSegment(StringBuilder b) {
  int index = b.lastIndexOf("/");
  if (index == -1) {
    b.setLength(0);
  } else {
    b.setLength(index);
  }
}

代码示例来源:origin: AdoptOpenJDK/jitwatch

public static String wordWrap(String text, int width)
{
  StringBuilder builder = new StringBuilder(text);
  int i = 0;
  while (i + width < builder.length() && (i = builder.lastIndexOf(S_SPACE, i + width)) != -1)
  {
    builder.replace(i, i + 1, S_NEWLINE);
  }
  return builder.toString();
}

代码示例来源:origin: AdoptOpenJDK/jitwatch

public static String wordWrap(String text, int width)
{
  StringBuilder builder = new StringBuilder(text);
  int i = 0;
  while (i + width < builder.length() && (i = builder.lastIndexOf(S_SPACE, i + width)) != -1)
  {
    builder.replace(i, i + 1, S_NEWLINE);
  }
  return builder.toString();
}

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

public static String join(final Collection collection, String delimiter) {
  if (collection == null || collection.size() == 0) {
    return EMPTY;
  }
  final StringBuilder sb = new StringBuilder(collection.size() * 16);
  for (Object element : collection) {
    sb.append((String) element);
    sb.append(delimiter);
  }
  return sb.toString().substring(0, sb.lastIndexOf(delimiter));
}

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

private String substituteNameFromMap(String name, Map<String, String> keywordMap) {
    StringBuilder sbName = new StringBuilder(name);
    int fromIndex = sbName.length();
    int equalIndex;
    while (-1 != (equalIndex = sbName.lastIndexOf("=", fromIndex))) {
      int commaIndex = sbName.lastIndexOf(",", equalIndex);
      String subName = sbName.substring(commaIndex + 1, equalIndex).trim();
      if (keywordMap.containsKey(subName)) {
        sbName.replace(commaIndex + 1, equalIndex, keywordMap.get(subName));
      }
      fromIndex = commaIndex;
    }
    return sbName.toString();
  }
}

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

@Override
  public String toString() {
    StringBuilder builder = new StringBuilder();
    for (Attribute<?, ?> attribute : attributes) {
      builder.append(attribute.getName()).append(".");
    }
    return builder.length() == 0 ? "" : builder.substring(0, builder.lastIndexOf("."));
  }
}

代码示例来源:origin: yanzhenjie/NoHttp

private <T> Where in(List<T> values) {
  builder.append(Options.IN).append(" (");
  String sep = ", ";
  for (T value : values) {
    if (value instanceof CharSequence)
      builder.append("'").append(value).append("'");
    else if (value instanceof Integer || value instanceof Long || value instanceof Short)
      builder.append(value);
    builder.append(sep);
  }
  if (builder.lastIndexOf(sep) > 0)
    builder.delete(builder.length() - 2, builder.length());
  builder.append(")");
  return this;
}

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

private CTEClause findCTEFromName(QB qb, String cteName) {
 StringBuilder qId = new StringBuilder();
 if (qb.getId() != null) {
  qId.append(qb.getId());
 }
 while (qId.length() > 0) {
  String nm = qId + ":" + cteName;
  CTEClause cte = aliasToCTEs.get(nm);
  if (cte != null) {
   return cte;
  }
  int lastIndex = qId.lastIndexOf(":");
  lastIndex = lastIndex < 0 ? 0 : lastIndex;
  qId.setLength(lastIndex);
 }
 return aliasToCTEs.get(cteName);
}

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

public static ConfigInfo merge(String dataId, String group, String tenant, List<ConfigInfoAggr> datumList) {
  StringBuilder sb = new StringBuilder();
  String appName = null;
  for (ConfigInfoAggr aggrInfo : datumList) {
    if (aggrInfo.getAppName() != null) {
      appName = aggrInfo.getAppName();
    }
    sb.append(aggrInfo.getContent());
    sb.append(Constants.NACOS_LINE_SEPARATOR);
  }
  String content = sb.substring(0, sb.lastIndexOf(Constants.NACOS_LINE_SEPARATOR));
  return new ConfigInfo(dataId, group, tenant, appName, content);
}

代码示例来源:origin: rest-assured/rest-assured

public void process( final HttpRequest req,
      final HttpContext context ) throws HttpException, IOException {
    
    // set the Accept-Encoding header:
    String encoding = getContentEncoding();            
    if ( !req.containsHeader( ACCEPT_ENC_HDR ) )
      req.addHeader( ACCEPT_ENC_HDR, encoding );
    else {
      StringBuilder values = new StringBuilder();
      for ( Header h : req.getHeaders( ACCEPT_ENC_HDR ) )
        values.append( h.getValue() ).append( "," );
      String encList = (!values.toString().contains( encoding )) ? values
          .append( encoding ).toString()
          : values.toString().substring( 0, values.lastIndexOf( "," ) );
          
      req.setHeader( ACCEPT_ENC_HDR, encList );
    }
    //TODO compress request and add content-encoding header.
  }
}

代码示例来源:origin: ReactiveX/RxJava

static final void scanFor(StringBuilder sourceCode, String annotation, String inDoc,
    StringBuilder e, String baseClassName) {
  int index = 0;
  for (;;) {
    int idx = sourceCode.indexOf(annotation, index);
    if (idx < 0) {
      break;
    }
    int j = sourceCode.lastIndexOf("/**", idx);
    // see if the last /** is not before the index (last time the annotation was found
    // indicating an uncommented method like subscribe()
    if (j > index) {
      int k = sourceCode.indexOf(inDoc, j);
      if (k < 0 || k > idx) {
        // when printed on the console, IDEs will create a clickable link to help navigate to the offending point
        e.append("java.lang.RuntimeException: missing ").append(inDoc).append(" section\r\n")
        ;
        int lc = lineNumber(sourceCode, idx);
        e.append(" at io.reactivex.").append(baseClassName)
        .append(" (").append(baseClassName).append(".java:")
        .append(lc).append(")").append("\r\n\r\n");
      }
    }
    index = idx + annotation.length();
  }
}

代码示例来源:origin: ReactiveX/RxJava

int j = sourceCode.lastIndexOf("/**", idx);

相关文章