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

Stringleft(String str, int length)
left
if (str == null) {
    return null;
if (length < 0) {
    return EMPTY;
if (str.length() <= length) {
    return str;
...
Stringright(String str, int length)
right
if (str == null) {
    return null;
if (length < 0) {
    return EMPTY;
if (str.length() <= length) {
    return str;
...
StringdelSuffix(String str)
del Suffix
int index = str.lastIndexOf(".");
if (index >= 0) {
    return str.substring(0, index);
} else {
    return str;
StringdeleteLast(String str, int num)
delete Last
if (str == null)
    return null;
return str.substring(0, str.length() - num);
StringdeleteLastIf(String str, String eq_str)
delete Last If
if (str == null)
    return null;
if (str.substring(str.length() - eq_str.length(), str.length())
        .equals(eq_str)) {
    return str.substring(0, str.length() - eq_str.length());
} else {
    return str;
StringgetTailorString(String string, int length)
get Tailor String
if (string == null) {
    return null;
if (string.length() <= length)
    return string;
StringBuilder sb = new StringBuilder(
        string.substring(0, length - 1));
sb.append(".");
...
Stringmid(String str, int beginIndex, int length)
mid
if (str == null) {
    return null;
if (length < 0 || beginIndex > str.length()) {
    return EMPTY;
if (beginIndex < 0) {
    beginIndex = 0;
...
StringsubStringByByte(String str, int startPos, int length)
sub String By Byte
if (str == null || str.length() == 0) {
    return "";
StringBuffer sb = new StringBuffer();
int byteLen = 0;
for (int i = 0; i < str.length(); i++) {
    int ascii = Character.codePointAt(str, i);
    if (ascii >= 0 && ascii <= 255) {
...
StringsubStringByByte(String paramString, int beginIndex, int endIndex)
sub String By Byte
if ((paramString == null) || (paramString.length() == 0)) {
    return "";
if (beginIndex >= endIndex) {
    return "";
int byteLength = 0;
String returnString = "";
...
StringsubString(String source, String start, int offsetStart, String end, int offsetEnd)
Substring
return source.substring(source.indexOf(start) + offsetStart,
        source.indexOf(offsetEnd) + offsetEnd);