判断字符串A中是否包含字符串B。
字符串B格式例如“北京*银行”,其中*号为通配符。意思就是说字符串B可能为“北京农业银行”或为“北京工商银行”或者就为“北京银行”。

解决方案 »

  1.   


    public static void main(String[] args){
    String a = "中国目前有北京银行、北京建设银行等";
    String b = "北京*银行";
    final Pattern pattern = Pattern.compile(b);   
    Matcher matcher = pattern.matcher(a);
    boolean result = matcher.find();
    System.out.println(result);
    }
      

  2.   

    public static void main(String[] args){    
        String a = "中国目前有北京农业银行、北京建设银行等";
        String b = "北京*银行";
        b = b.replaceAll("\\*", ".*");
        final Pattern pattern = Pattern.compile(b);   
        Matcher matcher = pattern.matcher(a);
        boolean result = matcher.find();
        System.out.println(result);
    }
      

  3.   

            String a = "中国北京农业银行朝阳区分行";
            String b = "北京*银行";
            Pattern rep = Pattern.compile(b.replace("*", ".*"));
            Matcher matcher = rep.matcher(a);
            if (matcher.find()) {
                System.out.println("A contains B");
                System.out.println(matcher.group());
            } else {
                System.out.println("A doesnot contains B");
            }
      

  4.   


    String b = "北京*银行";
    少写了个点,应该是String b = "北京.*银行";