/** * Purpose:不能與已知的字符串相同或部分相同 * @author Hermanwang * @param str : 要比較的字符串 * @param input : 輸入的字符串 * @return Boolean : 檢核結果 */ public static boolean inputSameAsStr(String str, String input) { //全都轉化為小寫 String strLower = str.toLowerCase(); String inputLower = input.toLowerCase(); //反转 String strReverseLower = new StringBuffer(strLower).reverse().toString(); boolean same = true; int strLength = str.length(); int inputLength = input.length(); if (strLength >= 3 && inputLength >= 3) { String newStr; for (int j = 0; j < inputLength; j ++) { newStr = inputLower.substring(j,j+3); if (strLower.indexOf(newStr) >= 0 || strReverseLower.indexOf(newStr) >= 0) { same = false; break; } if (j + 3 >= inputLength) { break; } } } return same; }