當數組argi具有多個分區時,它只能從數組的第二個url中找到單詞,但爲什麼?請在代碼中更正它。它在這裏的一部分: 我做搜索正規表示通過標題網址:完成java上的搜索邏輯
private final Pattern TITLE = Pattern.compile("\\<title\\>(.*)\\<\\/title\\>", Pattern.CASE_INSENSITIVE | Pattern.DOTALL);
而且searh邏輯在這裏:
public String search(String url, String someword) {
try {
InputStreamReader in = new InputStreamReader(new URL(url).openStream(),"UTF-8");
StringBuilder input = new StringBuilder();
int ch;
while ((ch = in.read()) != -1) {
input.append((char) ch);
}
if (Pattern.compile(someword, Pattern.CASE_INSENSITIVE).matcher(input).find()) {
Matcher title = TITLE.matcher(input);
if (title.find()) {
return title.group(1);
}
}
} catch (IOException e) {
e.printStackTrace();
} catch (PatternSyntaxException e) {
e.printStackTrace();
}
return null;
}
String[] argi = {"http://localhost:8080/site/dipnagradi","http://localhost:8080/site/contacts"};
for (int i = 0; i < argi.length; i++) {
String result = search(argi[i], word);
if (result != null) {
str = "Search phrase " + "<b>"+ word + "</b>" + " have found " + "<a href=\"" + argi[i] + "\">" + result + "</a>"+ "<p></p>";
}
else{
str="Search word not found!";
}
if (word == null||word=="") {
str = "Enter a search word!";
}
}
return null;
}
'如果(字== 「」)'ARRRRG MY EYES – user2336315
那一刻當你認爲「今天不會是'=='vs'equals'問題」.. – Maroun