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

StringsubstringBefore(String str, String separator)
substring Before
if (isEmpty(str) || separator == null) {
    return str;
if (separator.length() == 0) {
    return EMPTY;
int endIndex = str.indexOf(separator);
if (endIndex == INDEX_NOT_FOUND) {
...
StringsubstringBeforeLast(String str, String separator)
substring Before Last
if (isEmpty(str) || isEmpty(separator)) {
    return str;
int endIndex = str.lastIndexOf(separator);
if (endIndex == INDEX_NOT_FOUND) {
    return str;
return str.substring(0, endIndex);
...
StringunicodePreservingSubstring(String paramString, int paramInt1, int paramInt2)
unicode Preserving Substring
int i = unicodePreservingIndex(paramString, paramInt1);
int j = unicodePreservingIndex(paramString, paramInt2);
return paramString.substring(i, j);
StringunicodePreservingSubstring(String str, int begin, int end)
Returns a substring of str that respects Unicode character boundaries.
return str.substring(unicodePreservingIndex(str, begin),
        unicodePreservingIndex(str, end));
StringunicodePreservingSubstring(String str, int begin)
Equivalent to:
 #unicodePreservingSubstring(String,int,int) ( str, begin, str.length()) 
return unicodePreservingSubstring(str, begin, str.length());
StringsubstringAfter(String str, String separator)

Gets the substring after the first occurrence of a separator.

if (isEmpty(str)) {
    return str;
if (separator == null) {
    return EMPTY;
int pos = str.indexOf(separator);
if (pos == -1) {
...
StringsubstringBetween(String str, String open, String close)
Gets the String that is nested in between two Strings.
if (str == null || open == null || close == null) {
    return null;
int start = str.indexOf(open);
if (start != -1) {
    int end = str.indexOf(close, start + open.length());
    if (end != -1) {
        return str.substring(start + open.length(), end);
...
StringsubStringEndString(String sourceStr, String endString)
sub String End String
int position = sourceStr.indexOf(endString);
if (position == -1) {
    return sourceStr;
String newString = sourceStr.substring(0, position);
return newString;
SpannableStringBuilderhightLinghtString(String destStr, String subStr, int color)
hight Linght String
SpannableStringBuilder style = new SpannableStringBuilder(
        null == destStr ? "" : destStr);
if (null == destStr || "".equals(destStr) || "".equals(subStr)) {
    return style;
int start = destStr.lastIndexOf(subStr);
if (start != -1) {
    style.setSpan(new ForegroundColorSpan(color), start, start
...
Stringreplace(String source, String subject, String object)
replace
StringBuffer rtnStr = new StringBuffer();
String preStr = "";
String nextStr = source;
String srcStr = source;
while (srcStr.indexOf(subject) >= 0) {
    preStr = srcStr.substring(0, srcStr.indexOf(subject));
    nextStr = srcStr.substring(
            srcStr.indexOf(subject) + subject.length(),
...