cut Text to certain length - Android java.lang

Android examples for java.lang:String Shorten

Description

cut Text to certain length

Demo Code

import android.text.TextUtils;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Main{

    public static final String cutText(String text, int maxLength) {
        if (isEmpty(text) || maxLength < 0) {
            return text;
        }/* ww  w .  ja  v a 2s .  com*/
        int length = text.length();
        if (length > maxLength) {
            return text.substring(0, maxLength);
        }
        return text;
    }

}

Related Tutorials