首页 > 其他分享 >A字符串包含B字符串

A字符串包含B字符串

时间:2023-01-06 16:00:10浏览次数:40  
标签:target 包含 patternFlag containsFlag source 字符串 indexNum

A字符串包含B字符串

        String source = "china";
        String target = "INA";

        //contains true 包含
        boolean containsFlag = source.contains(target);
        //indexOf 1 包含 返回子字符串在当前字符串的位置,如果当前字符串不包含子字符串就返回-1
        int indexNum = source.indexOf(target);
        //java.util.regex
        boolean patternFlag = Pattern.compile(Pattern.quote(target), Pattern.CASE_INSENSITIVE).matcher(source).find();
        System.out.println("containsFlag==" + containsFlag);//containsFlag==false
        System.out.println("indexNum==" + indexNum);// indexNum==-1
        System.out.println("patternFlag==" + patternFlag);// patternFlag==true

标签:target,包含,patternFlag,containsFlag,source,字符串,indexNum
From: https://www.cnblogs.com/fightmonster/p/17030712.html

相关文章