Count substring In String - Android java.lang

Android examples for java.lang:String Substring

Description

Count substring In String

Demo Code

import android.text.TextUtils;
import java.io.UnsupportedEncodingException;
import java.nio.charset.Charset;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Main{

    public static int getCountInString(String str, String in) {

        String[] strArray = str.trim().split(in);
        int count = strArray.length - 1;
        if (count < 1) {
            count = 0;/* w  w w.j a  v  a  2  s  .c  o m*/
        }
        return count;

    }

}

Related Tutorials