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 source, int beginIndex, int endIndex)
Returns a string that is a substring of this string.
if (beginIndex < 0)
    throw new StringIndexOutOfBoundsException(beginIndex);
if (endIndex > source.length())
    throw new StringIndexOutOfBoundsException(endIndex);
int subLen = endIndex - beginIndex;
if (subLen < 0)
    throw new StringIndexOutOfBoundsException(subLen);
String toreturn = "";
...
Stringsubstring(String source, int length, String padding)
substring
if (source == null) {
    return "";
String s = source.trim();
char c;
int size = 0;
int count = s.length();
StringBuilder buffer = new StringBuilder();
...
Stringsubstring(String source, int offset, int dataLength)
substring
StringBuilder sb = new StringBuilder();
if (!isEmpty(source) && source.length() >= offset + dataLength) {
    sb.append(source.substring(offset, offset + dataLength));
return sb.toString();
Stringsubstring(String source, int size)
substring
return substring(source, 0, size);
Stringsubstring(String source, int startIndex)
substring
if (source == null)
    return null;
int length = source.length();
if (startIndex < 0)
    startIndex = 0;
if (length < startIndex)
    return "";
else
...
StringsubString(String source, int startIndex, int count)
sub String
if (source == null || source.equals("")) {
    return null;
if (source.length() - startIndex > count) {
    count = source.length() - startIndex;
if (startIndex <= 0) {
    startIndex = 0;
...
Stringsubstring(String src, int beginIndex, int endIndex)
substring
if (src.length() < beginIndex)
    return "";
return src.substring(beginIndex, endIndex);
Stringsubstring(String src, int start_idx, int end_idx)
substring
byte[] b = src.getBytes();
String tgt = "";
for (int i = start_idx; i <= end_idx; i++) {
    tgt += (char) b[i];
return tgt;
StringsubString(String src, int startIndex, int endIndex)
Find substring start by one index end by index
if ((startIndex == -1) || (endIndex == -1)) {
    return null;
return src.substring(startIndex, endIndex);
StringsubString(String src, String begin, String end)
sub String
return subString(src, 0, begin, end);