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 parentStr, String startStr, String endStr)
sub String
return parentStr.substring(parentStr.indexOf(startStr) + startStr.length(), parentStr.indexOf(endStr));
Stringsubstring(String S, int beginIndex, int endIndex)
substring
if (beginIndex < endIndex && beginIndex >= 0 && endIndex <= S.length()) {
    return S.substring(beginIndex, endIndex);
} else {
    return "";
Stringsubstring(String s, int beginIndex, int endIndex)
substring
while (beginIndex < endIndex && s.charAt(beginIndex) <= ' ')
    beginIndex++;
while (beginIndex < endIndex && s.charAt(endIndex - 1) <= ' ')
    endIndex--;
return beginIndex < endIndex ? s.substring(beginIndex, endIndex) : "";
Stringsubstring(String s, int i, String substring, int direction)
substring
if (direction >= 0) {
    return s.substring(i + substring.length());
} else {
    return s.substring(0, i);
StringsubString(String s, int length)
sub String
if (isBlank(s))
    return "";
if (s.getBytes().length <= length)
    return s;
char ch[] = null;
if (s.length() >= length)
    ch = s.substring(0, length).toCharArray();
else
...
Stringsubstring(String s, int start)
substring
if (s == null || start >= s.length()) {
    return "";
return s.substring(start);
Stringsubstring(String s, int start, int length)
Extract a substring from the given string, using start index and length of the extracted substring.
if (!hasLength(s)) {
    return s;
if (start < 0)
    start = 0;
if (start + 1 > s.length() || length < 0)
    return "";
return (start + length > s.length()) ? s.substring(start) : s.substring(start, start + length);
...
Stringsubstring(String s, int start, int stop)
substring
if (isEmpty(s)) {
    return s;
if (start < 0 || start >= s.length()) {
    return "";
if (stop > s.length() || stop < 0) {
    stop = s.length();
...
StringsubString(String s, int startIndex, int count)
slice up the given string
if (isEmpty(s)) {
    return "";
byte[] stringBytes = s.getBytes();
if (startIndex < 0) {
    startIndex = 0;
if (count > stringBytes.length - startIndex) {
...
Stringsubstring(String self, Integer startIndex, Integer endIndex)
substring
return self.substring(startIndex, endIndex);