Android Utililty Methods String Cut

List of utility methods to do String Cut

Description

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

Method

StringcutString(String source, String output, int slength)
cut String
String returnVal = null;
if (source != null) {
    if (source.length() > slength) {
        returnVal = source.substring(0, slength) + output;
    } else
        returnVal = source;
return returnVal;
...
StringcutString(String source, int slength)
cut String
String result = null;
if (source != null) {
    if (source.length() > slength) {
        result = source.substring(0, slength);
    } else
        result = source;
return result;
...
StringcutText(String text, int maxLength)
cut Text
if (isEmpty(text) || maxLength < 0) {
    return text;
int length = text.length();
if (length > maxLength) {
    return text.substring(0, maxLength);
return text;
...
StringsafeCut(String str, int length)
safe Cut
if (str.length() > length) {
    return str.substring(0, length) + "...";
return str;
StringsafeCutNoDot(String str, int length)
safe Cut No Dot
if (str.length() > length) {
    return str.substring(0, length);
return str;
StringcutString(String str, int length)
cut String
return cutString(str, length, "");
StringcutString(String str, int length, String dot)
cut String
int strBLen = strlen(str, "GBK");
if (strBLen <= length) {
    return str;
int temp = 0;
StringBuffer sb = new StringBuffer(length);
char[] ch = str.toCharArray();
for (char c : ch) {
...
StringcutStringFromChar(String str1, String str2, int offset)
cut String From Char
if (isEmpty(str1)) {
    return "";
int start = str1.indexOf(str2);
if (start != -1) {
    if (str1.length() > start + offset) {
        return str1.substring(start + offset);
return "";
StringcutRight(final String srcStr, final String cutStr)
cut Right
if (srcStr == null || cutStr == null) {
    return srcStr;
String retStr = srcStr;
if (retStr.endsWith(cutStr)) {
    retStr = retStr.substring(0, retStr.length() - cutStr.length()); 
return retStr;
...
Stringcutoff(String value, int length)
cutoff
if (isNullOrEmpty(value) == false && value.length() > length) {
    return value.substring(0, length - 1) + "..";
return value;