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

StringreplaceOnce(String source, String subject, String object)
replace Once
StringBuffer rtnStr = new StringBuffer();
String preStr = "";
String nextStr = source;
if (source.indexOf(subject) >= 0) {
    preStr = source.substring(0, source.indexOf(subject));
    nextStr = source.substring(
            source.indexOf(subject) + subject.length(),
            source.length());
...
Stringsubstring(String str, int toCount)
substring
return substring(str, toCount, "..");
Stringsubstring(String str, int len, String more)
substring
if (str == null || "".equals(str) || len < 1) {
    return "";
char[] chars = str.toCharArray();
int count = 0;
int charIndex = 0;
for (int i = 0; i < chars.length; i++) {
    int charLength = getCharLen(chars[i]);
...
StringsubstringFromLast(final String str, final String separator)
substring From Last
if (isEmpty(str) || isEmpty(separator)) {
    return str;
int pos = str.lastIndexOf(separator);
if (pos == -1) {
    return str;
return str.substring(0, pos);
...
StringsubstringToLast(final String str, final String separator)
substring To Last
if (isEmpty(str) || isEmpty(separator)) {
    return str;
int pos = str.lastIndexOf(separator);
if (pos == -1) {
    return str;
return str.substring(pos + 1, str.length());
...
StringtakeOutFirstChar(String input)
take Out First Char
if (input.charAt(0) == '#') {
    String re = input.substring(1, input.length());
    return re;
return input;
Stringsubstring(String str, int srcPos, int specialCharsLength)
substring
if (str == null || "".equals(str) || specialCharsLength < 1) {
    return "";
if (srcPos < 0) {
    srcPos = 0;
if (specialCharsLength <= 0) {
    return "";
...
StringsubstringAfter(String text, char c)
Gives the substring of the given text after the given separator.
if (isEmpty(text)) {
    return text;
int cPos = text.indexOf(c);
if (cPos < 0) {
    return "";
return text.substring(cPos + 1);
...
StringsubstringAfterLast(String text, char separator)
Gives the substring of the given text after the last occurrence of the given separator.
if (isEmpty(text)) {
    return text;
int cPos = text.lastIndexOf(separator);
if (cPos < 0) {
    return "";
return text.substring(cPos + 1);
...
StringsubstringBefore(String text, char separator)
Gives the substring of the given text before the given separator.
if (isEmpty(text))
    return text;
int sepPos = text.indexOf(separator);
if (sepPos < 0)
    return text;
return text.substring(0, sepPos);