有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!


共 (5) 个答案

  1. # 1 楼答案

    public static boolean checkIfPasswordMatchUName(final String userName, final String passWd) {
    
        if (userName.isEmpty() || passWd.isEmpty() || passWd.length() > userName.length()) {
            return false;
        }
        int checkLength = 3;
        for (int outer = 0; (outer + checkLength) < passWd.length()+1; outer++) {
            String subPasswd = passWd.substring(outer, outer+checkLength);
            if(userName.contains(subPasswd)) {
                return true;
            }
            if(outer > (passWd.length()-checkLength))
                break;
        }
        return false;
    }
    
  2. # 2 楼答案

    String.indexOf(String)

    对于不区分大小写的搜索,在原始字符串和indexOf之前的子字符串上都使用toUpperCase或toLowerCase

    String full = "my template string";
    String sub = "Template";
    boolean fullContainsSub = full.toUpperCase().indexOf(sub.toUpperCase()) != -1;
    
  3. # 3 楼答案

    使用正则表达式并将其标记为不区分大小写:

    if (myStr.matches("(?i).*template.*")) {
      // whatever
    }
    

    (?i)打开大小写不敏感和*在搜索词的每一端匹配任何周围的字符(因为String.matches适用于整个字符串)

  4. # 4 楼答案

    String word = "cat";
    String text = "The cat is on the table";
    Boolean found;
    
    found = text.contains(word);
    
  5. # 5 楼答案

    您可以使用indexOf()和toLowerCase()对子字符串进行不区分大小写的测试

    String string = "testword";
    boolean containsTemplate = (string.toLowerCase().indexOf("template") >= 0);