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

StringsubstringBefore(String str, int endChar)
substring Before
if (str == null) {
    return null;
if (endChar < 0) {
    return str;
int idx = str.indexOf(endChar);
if (idx == -1) {
...
StringsubstringBefore(String str, String separator)
substring Before
if (isEmpty(str) || separator == null) {
    return str;
if (separator.length() == 0) {
    return EMPTY;
int pos = str.indexOf(separator);
if (pos == -1) {
...
StringsubstringBefore(String str, String separator)
substring Before
int index = str.indexOf(separator);
if (index == -1) {
    return str;
return str.substring(0, index);
StringsubstringBefore(String str, String separator)
substring Before
if (isEmpty(str) || separator == null) {
    return str;
if (separator.length() == 0) {
    return EMPTY;
int pos = str.indexOf(separator);
if (pos == INDEX_NOT_FOUND) {
...
StringsubstringBefore(String string, String delimiter)
Returns the substring before the first occurrence of a delimiter.
int pos = string.indexOf(delimiter);
return pos >= 0 ? string.substring(0, pos) : string;
StringsubstringBefore(String text, String str)
substring Before
int idx = text.indexOf(str);
if (idx != -1) {
    return text.substring(0, idx);
} else {
    return null;
StringsubstringBeforeChar(String str, int separator)
Return the substring before the first occurrence of a separator.
if (isEmpty(str)) {
    return str;
int pos = str.indexOf(separator);
if (pos < 0) {
    return str;
return str.substring(0, pos);
...
StringsubstringBeforeFirst(String string, String delimiter)
substring Before First
final int index = string.indexOf(delimiter);
if (index == -1) {
    return "";
return string.substring(0, index);
StringsubStringBeforeFirstTab(final String s)
Get the first field of a line
if (s == null) {
    return null;
final int indexFirstTab = s.indexOf('\t');
if (indexFirstTab == -1) {
    return s;
return s.substring(0, indexFirstTab);
...
StringsubstringBeforeLast(final String str, final String separator)
substring Before Last
if (isEmpty(str) || isEmpty(separator)) {
    return str;
final int pos = str.lastIndexOf(separator);
if (pos == INDEX_NOT_FOUND) {
    return str;
return str.substring(0, pos);
...