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 str, int start, int end)
substring
if (str == null)
    return null;
byte[] data = str.getBytes();
if (data.length < start) {
    return "";
int realEnd = end >= data.length ? data.length : end;
int length = realEnd - start;
...
Stringsubstring(String str, int start, int end)
Find substring of a string.
String result = "";
if (str != null) {
    try {
        result = str.substring(start, end);
    } catch (Exception e) {
return result;
...
StringsubString(String str, int start, int end)
sub String
int strLen = str.length();
start = start > strLen ? strLen : start;
start = start > 0 ? start : 0;
if (end == -1) {
    end = strLen;
} else {
    end = end > strLen ? strLen : end;
return str.substring(start, end);
Stringsubstring(String str, int toCount)
substring
if (str == null)
    return "";
int reInt = 0;
StringBuilder reStr = new StringBuilder();
char[] tempChar = str.toCharArray();
int len = tempChar.length;
for (int kk = 0; (kk < len && toCount > reInt); kk++) {
    char currentChar = tempChar[kk];
...
Stringsubstring(String str, int toCount, String more)
substring
int reInt = 0;
String reStr = "";
if (str == null)
    return "";
char[] tempChar = str.toCharArray();
for (int kk = 0; (kk < tempChar.length && toCount > reInt); kk++) {
    String s1 = str.valueOf(tempChar[kk]);
    byte[] b = s1.getBytes();
...
Stringsubstring(String str, String delim)
substring
return substring(str, delim, false);
StringsubString(String string, int beginIndex, int length)
Gets the sub string of the given string.
final int endIndex = beginIndex + length;
if (beginIndex >= string.length()) {
    return EMPTY;
if (endIndex > string.length()) {
    return string.substring(beginIndex, string.length());
return string.substring(beginIndex, endIndex);
...
StringsubString(String string, int index)
sub String
if (string == null)
    return null;
return string.substring(index);
Stringsubstring(String string, int init, int end)
Extrae una subcadena, donde los indices pueden ser negativos
if (init < 0) {
    init += string.length();
if (end < 0) {
    end += string.length();
return string.substring(init, end);
Stringsubstring(String string, int maxChars, String suffix)
substring
if (string.length() > maxChars) {
    return string.substring(0, maxChars - 1) + suffix;
return string;