Java Utililty Methods String Sub String

List of utility methods to do String Sub String

Description

The list of methods to do String Sub String are organized into topic(s).

Method

StringSubString(String x, long y)
Sub String
return x.substring((int) y);
Stringsubstring(StringBuffer buf, int start, int lim)
substring
int len = lim - start;
char[] result = new char[len];
buf.getChars(start, lim, result, 0);
return String.valueOf(result);
Stringsubstring2ByteString(String str, int endIndex)
substring Byte String
if (str == null) {
    return null;
byte[] strByte = str.getBytes();
int i, strLen;
strLen = strByte.length;
if (strLen <= endIndex) {
    return str;
...
StringsubString4lastIndex(String string, String regex)
sub Stringlast Index
if (isNullOrEmpty(string) || isNullOrEmpty(regex)) {
    return string;
if (string.indexOf(regex) == -1) {
    return string;
return string.substring(string.lastIndexOf(regex) + regex.length());
StringsubstringAfter(final String str, final String separator)
substring After
if (isEmpty(str)) {
    return str;
if (separator == null) {
    return EMPTY;
final int pos = str.indexOf(separator);
if (pos == INDEX_NOT_FOUND) {
...
StringsubstringAfter(String s, String cs)
substring After
int idx = s.indexOf(cs);
if (idx >= 0) {
    return s.substring(idx + cs.length());
} else {
    return null;
StringsubstringAfter(String s, String substr, boolean fromend)
Return the string after a given substring
int p = fromend ? s.lastIndexOf(substr) : s.indexOf(substr);
return (p >= 0) ? s.substring(p + 1) : s;
StringsubstringAfter(String sourceStr, String expr)
substring After
if (isEmpty(sourceStr) || expr == null) {
    return sourceStr;
if (expr.length() == 0) {
    return sourceStr;
int pos = sourceStr.indexOf(expr);
if (pos == -1) {
...
StringsubstringAfter(String str, int beginChar, boolean last)
substring After
if (str == null) {
    return null;
if (beginChar < 0) {
    return str;
int idx = (last) ? str.lastIndexOf(beginChar) : str.indexOf(beginChar);
if (idx == -1) {
...
StringsubstringAfter(String str, String delimiter)
substring After
int indexOf = str.indexOf(delimiter);
return str.substring(indexOf + delimiter.length(), str.length());