if string Contains a substring by separator - Android java.lang

Android examples for java.lang:String Substring

Description

if string Contains a substring by separator

Demo Code

import android.util.Log;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.text.DecimalFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Main{

    /**/*from   w w  w  .  j  ava  2s  . co m*/
     * <br> StringUtil.defStrContains("1|2,3"|"1","|") =true
     * <br> StringUtil.defStrContains("1|2|3","3","|") =true
     * <br> StringUtil.defStrContains("1|2|3","2","|") =true
     * <br> StringUtil.defStrContains("1|2|3","4","|") =false
     * <br> StringUtil.defStrContains("1|2|3","","|") =false
     * <br> StringUtil.defStrContains("1|2|3",null,"|") =false
     * <br> <b>StringUtil.defStrContains("1|2|3","1|2","|") =true</b>
     * <br> StringUtil.defStrContains("1|2|3","|2|","|") =true
     * <br> StringUtil.defStrContains("1|2|3","|2|",",") =true
     * <br> StringUtil.defStrContains("1|2|3","2",",") =false
     * @return
     */
    public static boolean defStrContains(String defStr, String defValue,
            String splitSyb) {
        return (splitSyb + defStr + splitSyb).contains(splitSyb + defValue
                + splitSyb);
    }

}

Related Tutorials