Android Utililty Methods String Sub String Get

List of utility methods to do String Sub String Get

Description

The list of methods to do String Sub String Get are organized into topic(s).

Method

StringsubString(String str, int length)
sub String
if (isBlank(str)) {
    return "";
} else if (str.length() > length) {
    return str.substring(0, length);
} else {
    return str;
StringsubInStringByFlag(String str, String flag)
sub In String By Flag
if (isBlank(str))
    return null;
StringBuffer sb = new StringBuffer(str);
int index = str.lastIndexOf(flag);
if (index < 0) {
    return str;
} else {
    str = sb.delete(sb.length() - flag.length(), sb.length())
...
StringsubstringWithoutException(String text, int startIndex, int endIndex)
substring Without Exception
if (isNullOrEmpty(text) || startIndex >= text.length()) {
    return "";
final StringBuilder stringBuilder = new StringBuilder();
final int realEndIndex = endIndex >= text.length() ? text.length() - 1
        : endIndex;
for (int i = startIndex; i <= realEndIndex; i++) {
    stringBuilder.append(text.charAt(i));
...
StringsubString(String str)
sub String
str = Html.fromHtml(str, null, null).toString();
String temp = String.valueOf(str.charAt(str.length() - 1));
if (temp.matches(E1)) {
    return str.substring(0, str.length() - 2);
return str.substring(0, str.length() - 1);
Stringreplace(String s, String oldSub, String newSub)
replace
if ((s == null) || (oldSub == null) || (newSub == null)) {
    return null;
int y = s.indexOf(oldSub);
if (y >= 0) {
    StringBuffer sb = new StringBuffer();
    int length = oldSub.length();
    int x = 0;
...
Stringreplace(String s, String[] oldSubs, String[] newSubs)
replace
if ((s == null) || (oldSubs == null) || (newSubs == null)) {
    return null;
if (oldSubs.length != newSubs.length) {
    return s;
for (int i = 0; i < oldSubs.length; i++) {
    s = replace(s, oldSubs[i], newSubs[i]);
...
Stringsubstring(String str, int beginIndex)
substring
if (str == null) {
    return null;
if (beginIndex < 0) {
    return EMPTY;
if (beginIndex > str.length()) {
    return EMPTY;
...
Stringsubstring(String str, int beginIndex, int endIndex)
substring
if (str == null) {
    return null;
if (beginIndex < 0 || endIndex < 0) {
    return EMPTY;
if (endIndex > str.length()) {
    endIndex = str.length();
...
StringsubstringAfter(String str, String separator)
substring After
if (isEmpty(str)) {
    return str;
if (separator == null) {
    return EMPTY;
int beginIndex = str.indexOf(separator);
if (beginIndex == INDEX_NOT_FOUND) {
...
StringsubstringAfterLast(String str, String separator)
substring After Last
if (isEmpty(str)) {
    return str;
if (isEmpty(separator)) {
    return EMPTY;
int beginIndex = str.lastIndexOf(separator);
if (beginIndex == INDEX_NOT_FOUND) {
...