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

StringsubstringL(String s, int i, int len)
substring L
String res = s.substring(i, Math.min(i + len, s.length()));
return res;
StringsubstringLinesWithTokenOfEOL(String originalString, String stringToBeInserted)
Method to process String value with EOL mark
StringBuffer processedString = new StringBuffer();
int lastEnd = 0;
for (int i = 0; i <= originalString.length(); i++) {
    if (i + 5 <= originalString.length()) {
        if (originalString.substring(i, i + 5).equals("#EOL#")) {
            processedString.append(originalString.substring(lastEnd, i));
            processedString.append(stringToBeInserted);
            lastEnd = i + 5;
...
booleansubstringMatch(CharSequence str, int index, CharSequence substring)
Test whether the given string matches the given substring at the given index.
for (int j = 0; j < substring.length(); j++) {
    int i = index + j;
    if (i >= str.length() || str.charAt(i) != substring.charAt(j)) {
        return false;
return true;
booleansubstringMatch(CharSequence str, int index, CharSequence substring)
substring Match
for (int j = 0; j < substring.length(); j++) {
    int i = index + j;
    if (i >= str.length() || str.charAt(i) != substring.charAt(j)) {
        return false;
return true;
booleansubstringMatches(final String source, final String substring, final boolean checkBoundaries)
substring Matches
if (source == null) {
    return false;
if (substring == null || substring.length() == 0) {
    return true;
int index = source.indexOf(substring);
if (index == -1) {
...
StringsubstringMore(String s, int maxlen)
substring More
if (s.length() < maxlen) {
    return s;
} else {
    return (maxlen < 3 ? "" : s.substring(0, maxlen - 3)) + "...";
StringsubStringNobit(String str, int toCount, String more)
sub String Nobit
if (str != null) {
    if (str.getBytes().length > toCount) {
        return subStringByBytes(str, toCount, more);
    } else {
        return str;
} else {
    return "";
...
StringsubStringNotEncode(String subject, int size)
sub String Not Encode
if ((subject != null) && (subject.length() > size))
    subject = subject.substring(0, size) + "...";
return subject;
StringsubStringRight(String str, int length)
sub String Right
if (str == null || str.isEmpty())
    return str;
return str.substring(str.length() - min(str.length(), length));
Stringsubstrings(String str, int start, int end)
substrings
if (str == null) {
    return null;
int length = end - start;
byte[] dest = new byte[length];
System.arraycopy(str.getBytes(), start, dest, 0, length);
return new String(dest);