本文整理了Java中java.lang.String.lastIndexOf()
方法的一些代码示例,展示了String.lastIndexOf()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。String.lastIndexOf()
方法的具体详情如下:
包路径:java.lang.String
类名称:String
方法名:lastIndexOf
[英]Returns the index within this string of the last occurrence of the specified character. For values of ch
in the range from 0 to 0xFFFF (inclusive), the index (in Unicode code units) returned is the largest value k such that:
this.charAt(k) == ch
is true. For other values of ch
, it is the largest value k such that:
this.codePointAt(k) == ch
is true. In either case, if no such character occurs in this string, then -1
is returned. The String
is searched backwards starting at the last character.
[中]返回此字符串中指定字符最后一次出现的索引。对于介于0到0xFFFF(含)之间的ch
值,返回的索引(以Unicode代码单位表示)是最大值k,因此:
this.charAt(k) == ch
为真。对于ch
的其他值,它是最大值k,因此:
this.codePointAt(k) == ch
为真。在任何一种情况下,如果此字符串中没有出现此类字符,则返回-1
。String
从最后一个字符开始向后搜索。
代码示例来源:origin: google/guava
/**
* Returns the package name of {@code classFullName} according to the Java Language Specification
* (section 6.7). Unlike {@link Class#getPackage}, this method only parses the class name, without
* attempting to define the {@link Package} and hence load files.
*/
public static String getPackageName(String classFullName) {
int lastDot = classFullName.lastIndexOf('.');
return (lastDot < 0) ? "" : classFullName.substring(0, lastDot);
}
代码示例来源:origin: spring-projects/spring-framework
/**
* Unqualify a string qualified by a separator character. For example,
* "this:name:is:qualified" returns "qualified" if using a ':' separator.
* @param qualifiedName the qualified name
* @param separator the separator
*/
public static String unqualify(String qualifiedName, char separator) {
return qualifiedName.substring(qualifiedName.lastIndexOf(separator) + 1);
}
代码示例来源:origin: spring-projects/spring-framework
/**
* Determine the name of the package of the given fully-qualified class name,
* e.g. "java.lang" for the {@code java.lang.String} class name.
* @param fqClassName the fully-qualified class name
* @return the package name, or the empty String if the class
* is defined in the default package
*/
public static String getPackageName(String fqClassName) {
Assert.notNull(fqClassName, "Class name must not be null");
int lastDotIndex = fqClassName.lastIndexOf(PACKAGE_SEPARATOR);
return (lastDotIndex != -1 ? fqClassName.substring(0, lastDotIndex) : "");
}
代码示例来源:origin: spring-projects/spring-framework
/**
* Extract the URL filename from the given request URI.
* @param uri the request URI; for example {@code "/index.html"}
* @return the extracted URI filename; for example {@code "index"}
*/
protected String extractViewNameFromUrlPath(String uri) {
int start = (uri.charAt(0) == '/' ? 1 : 0);
int lastIndex = uri.lastIndexOf('.');
int end = (lastIndex < 0 ? uri.length() : lastIndex);
return uri.substring(start, end);
}
代码示例来源:origin: spring-projects/spring-framework
/**
* Determine the name of the class file, relative to the containing
* package: e.g. "String.class"
* @param clazz the class
* @return the file name of the ".class" file
*/
public static String getClassFileName(Class<?> clazz) {
Assert.notNull(clazz, "Class must not be null");
String className = clazz.getName();
int lastDotIndex = className.lastIndexOf(PACKAGE_SEPARATOR);
return className.substring(lastDotIndex + 1) + CLASS_FILE_SUFFIX;
}
代码示例来源:origin: apache/incubator-dubbo
public static String simpleClassName(Class<?> clazz) {
if (clazz == null) {
throw new NullPointerException("clazz");
}
String className = clazz.getName();
final int lastDotIdx = className.lastIndexOf(PACKAGE_SEPARATOR_CHAR);
if (lastDotIdx > -1) {
return className.substring(lastDotIdx + 1);
}
return className;
}
代码示例来源:origin: stackoverflow.com
private static String getSubmittedFileName(Part part) {
for (String cd : part.getHeader("content-disposition").split(";")) {
if (cd.trim().startsWith("filename")) {
String fileName = cd.substring(cd.indexOf('=') + 1).trim().replace("\"", "");
return fileName.substring(fileName.lastIndexOf('/') + 1).substring(fileName.lastIndexOf('\\') + 1); // MSIE fix.
}
}
return null;
}
代码示例来源:origin: spring-projects/spring-framework
@Override
public String extractVersion(String requestPath) {
Matcher matcher = pattern.matcher(requestPath);
if (matcher.find()) {
String match = matcher.group(1);
return (match.contains("-") ? match.substring(match.lastIndexOf('-') + 1) : match);
}
else {
return null;
}
}
代码示例来源:origin: spring-projects/spring-framework
@Override
@Nullable
public String extractVersion(String requestPath) {
Matcher matcher = pattern.matcher(requestPath);
if (matcher.find()) {
String match = matcher.group(1);
return (match.contains("-") ? match.substring(match.lastIndexOf('-') + 1) : match);
}
else {
return null;
}
}
代码示例来源:origin: spring-projects/spring-framework
private String getEntityName(Class<?> entityClass) {
String shortName = ClassUtils.getShortName(entityClass);
int lastDot = shortName.lastIndexOf('.');
if (lastDot != -1) {
return shortName.substring(lastDot + 1);
}
else {
return shortName;
}
}
代码示例来源:origin: google/guava
@Override
public int lastIndexOf(@Nullable Object object) {
return (object instanceof Character) ? string.lastIndexOf((Character) object) : -1;
}
代码示例来源:origin: google/guava
private static @Nullable String convertDottedQuadToHex(String ipString) {
int lastColon = ipString.lastIndexOf(':');
String initialPart = ipString.substring(0, lastColon + 1);
String dottedQuad = ipString.substring(lastColon + 1);
byte[] quad = textToNumericFormatV4(dottedQuad);
if (quad == null) {
return null;
}
String penultimate = Integer.toHexString(((quad[0] & 0xff) << 8) | (quad[1] & 0xff));
String ultimate = Integer.toHexString(((quad[2] & 0xff) << 8) | (quad[3] & 0xff));
return initialPart + penultimate + ":" + ultimate;
}
代码示例来源:origin: apache/incubator-dubbo
public URL setAddress(String address) {
int i = address.lastIndexOf(':');
String host;
int port = this.port;
if (i >= 0) {
host = address.substring(0, i);
port = Integer.parseInt(address.substring(i + 1));
} else {
host = address;
}
return new URL(protocol, username, password, host, port, path, getParameters());
}
代码示例来源:origin: spring-projects/spring-framework
public static Method findMethod(String desc, ClassLoader loader) {
try {
int lparen = desc.indexOf('(');
int dot = desc.lastIndexOf('.', lparen);
String className = desc.substring(0, dot).trim();
String methodName = desc.substring(dot + 1, lparen).trim();
return getClass(className, loader).getDeclaredMethod(methodName, parseTypes(desc, loader));
}
catch (ClassNotFoundException | NoSuchMethodException ex) {
throw new CodeGenerationException(ex);
}
}
代码示例来源:origin: spring-projects/spring-framework
private void adaptForwardedHost(String hostToUse) {
int portSeparatorIdx = hostToUse.lastIndexOf(':');
if (portSeparatorIdx > hostToUse.lastIndexOf(']')) {
host(hostToUse.substring(0, portSeparatorIdx));
port(Integer.parseInt(hostToUse.substring(portSeparatorIdx + 1)));
}
else {
host(hostToUse);
port(null);
}
}
代码示例来源:origin: apache/incubator-dubbo
private List<URL> toUrlsWithEmpty(URL consumer, String path, List<String> providers) {
List<URL> urls = toUrlsWithoutEmpty(consumer, providers);
if (urls == null || urls.isEmpty()) {
int i = path.lastIndexOf(Constants.PATH_SEPARATOR);
String category = i < 0 ? path : path.substring(i + 1);
URL empty = consumer.setProtocol(Constants.EMPTY_PROTOCOL).addParameter(Constants.CATEGORY_KEY, category);
urls.add(empty);
}
return urls;
}
代码示例来源:origin: spring-projects/spring-framework
private String getInputTag(String output) {
int inputStart = output.indexOf("<", 1);
int inputEnd = output.lastIndexOf(">", output.length() - 2);
return output.substring(inputStart, inputEnd + 1);
}
代码示例来源:origin: spring-projects/spring-framework
private String getFormTag(String output) {
int inputStart = output.indexOf("<", 1);
int inputEnd = output.lastIndexOf(">", output.length() - 2);
return output.substring(0, inputStart) + output.substring(inputEnd + 1);
}
代码示例来源:origin: spring-projects/spring-framework
@Nullable
private String decodeAndNormalizePath(@Nullable String path, HttpServletRequest request) {
if (path != null) {
path = getUrlPathHelper().decodeRequestString(request, path);
if (path.charAt(0) != '/') {
String requestUri = getUrlPathHelper().getRequestUri(request);
path = requestUri.substring(0, requestUri.lastIndexOf('/') + 1) + path;
path = StringUtils.cleanPath(path);
}
}
return path;
}
代码示例来源:origin: spring-projects/spring-framework
protected final void assertBlockTagContains(String output, String desiredContents) {
String contents = output.substring(output.indexOf(">") + 1, output.lastIndexOf("<"));
assertTrue("Expected to find '" + desiredContents + "' in the contents of block tag '" + output + "'",
contents.contains(desiredContents));
}
内容来源于网络,如有侵权,请联系作者删除!