本文整理了Java中java.lang.String.substring()
方法的一些代码示例,展示了String.substring()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。String.substring()
方法的具体详情如下:
包路径:java.lang.String
类名称:String
方法名:substring
[英]Returns a new string that is a substring of this string. The substring begins with the character at the specified index and extends to the end of this string.
Examples:
"unhappy".substring(2) returns "happy"
"Harbison".substring(3) returns "bison"
"emptiness".substring(9) returns "" (an empty string)
[中]返回作为此字符串的子字符串的新字符串。子字符串以指定索引处的字符开头,并延伸到此字符串的结尾。
示例:
"unhappy".substring(2) returns "happy"
"Harbison".substring(3) returns "bison"
"emptiness".substring(9) returns "" (an empty string)
代码示例来源:origin: square/okhttp
private static String secondaryName(String javaName) {
if (javaName.startsWith("TLS_")) {
return "SSL_" + javaName.substring(4);
} else if (javaName.startsWith("SSL_")) {
return "TLS_" + javaName.substring(4);
} else {
return javaName;
}
}
代码示例来源: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: google/guava
@VisibleForTesting
static String getClassName(String filename) {
int classNameEnd = filename.length() - CLASS_FILE_NAME_EXTENSION.length();
return filename.substring(0, classNameEnd).replace('/', '.');
}
代码示例来源:origin: square/okhttp
/** Add an header line containing a field name, a literal colon, and a value. */
public Builder add(String line) {
int index = line.indexOf(":");
if (index == -1) {
throw new IllegalArgumentException("Unexpected header: " + line);
}
return add(line.substring(0, index).trim(), line.substring(index + 1));
}
代码示例来源:origin: google/guava
@Override
Optional<String> chop(String str) {
if (str.endsWith(suffix)) {
return Optional.of(str.substring(0, str.length() - suffix.length()));
} else {
return Optional.absent();
}
}
};
代码示例来源:origin: square/okhttp
@FromJson HttpUrl urlFromJson(String urlString) {
if (urlString.startsWith("wss:")) urlString = "https:" + urlString.substring(4);
if (urlString.startsWith("ws:")) urlString = "http:" + urlString.substring(3);
return HttpUrl.get(urlString);
}
}
代码示例来源: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: google/guava
private static String firstCharOnlyToUpper(String word) {
return word.isEmpty()
? word
: Ascii.toUpperCase(word.charAt(0)) + Ascii.toLowerCase(word.substring(1));
}
}
代码示例来源:origin: google/guava
@Override
public String apply(String from) {
return (from.length() == 0) ? from : from.substring(1);
}
}
代码示例来源:origin: google/guava
@Override
public String apply(String from) {
return ((from == null) || "".equals(from)) ? null : from.substring(1);
}
};
代码示例来源:origin: google/guava
String consumeTokenIfPresent(CharMatcher matcher) {
checkState(hasMore());
int startPosition = position;
position = matcher.negate().indexIn(input, startPosition);
return hasMore() ? input.substring(startPosition, position) : input.substring(startPosition);
}
代码示例来源:origin: ReactiveX/RxJava
@Override
public Object apply(Integer v) throws Exception {
return Thread.currentThread().getName().substring(0, 4);
}
}),
代码示例来源:origin: ReactiveX/RxJava
@Override
public Object apply(Integer v) throws Exception {
return Thread.currentThread().getName().substring(0, 4);
}
})
代码示例来源:origin: ReactiveX/RxJava
@Override
public Object apply(Integer v) throws Exception {
return Thread.currentThread().getName().substring(0, 4);
}
}),
代码示例来源:origin: ReactiveX/RxJava
@Override
public Object apply(Integer v) throws Exception {
return Thread.currentThread().getName().substring(0, 4);
}
}),
代码示例来源:origin: ReactiveX/RxJava
@Override
public Object apply(Integer v) throws Exception {
return Thread.currentThread().getName().substring(0, 4);
}
}),
代码示例来源:origin: ReactiveX/RxJava
@Override
public Object apply(Integer v) throws Exception {
return Thread.currentThread().getName().substring(0, 4);
}
}),
代码示例来源:origin: ReactiveX/RxJava
@Override
public Object apply(Integer v) throws Exception {
return Thread.currentThread().getName().substring(0, 4);
}
}),
代码示例来源:origin: ReactiveX/RxJava
@Override
public Object apply(Integer v) throws Exception {
return Thread.currentThread().getName().substring(0, 4);
}
})
代码示例来源:origin: square/okhttp
/** Equivalent to {@code string.substring(pos, limit).trim()}. */
public static String trimSubstring(String string, int pos, int limit) {
int start = skipLeadingAsciiWhitespace(string, pos, limit);
int end = skipTrailingAsciiWhitespace(string, start, limit);
return string.substring(start, end);
}
内容来源于网络,如有侵权,请联系作者删除!