cut String By length and show ... - Android java.lang

Android examples for java.lang:String Shorten

Description

cut String By length and show ...

Demo Code

import android.net.Uri;
import android.text.SpannableString;
import android.text.Spanned;
import android.text.TextUtils;
import android.text.style.StrikethroughSpan;
import android.util.Log;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.io.UnsupportedEncodingException;
import java.math.BigDecimal;
import java.security.NoSuchAlgorithmException;
import java.text.DecimalFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.HashMap;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Main{

    public static String cutStringByNum(String content, int num,
            String endString) {/*  w w  w.  j  a  va2s  .  c  om*/
        String end = endString;
        if (end == null) {
            end = "...";
        }
        String str = "";
        if (content.length() > num) {
            str = content.substring(0, num) + end;
        } else {
            str = content;
        }
        return str;
    }

}

Related Tutorials