這一定很簡單,但我很困難。您看到我正在嘗試在另一個字符串中查找字符串,如下所示。爲什麼Java String indexOf失敗?
e = input.indexOf("-->");
s = input.indexOf("<!--");
input = input.replace(input.substring(s, e + 3), " ");
的整數e和s的返回-1,因爲它沒有被發現,這是導致替代方法失敗。我正在使用的測試字符串是"Chartered Certified<!--lol--> Accountants (ACCA)"
。我試圖創造一個新的字符串對象,並在字符串中作爲參數傳遞如下
e=input.indexOf(new String("<!--"));
這產生相同的結果。 任何想法?
這是一段獨立的代碼,我寫的很完美。
public static void main(String[] args) {
int e = 0;
int s = 0;
while (e != -1) {
//input.replace("\"", "\'");
e = input.indexOf("-->");
s = input.indexOf("<!--");
input = input.replace(input.substring(s, e + 3), " ");
e = input.indexOf("-->");
System.out.println(input);
}
}
但我似乎無法看到爲什麼它失敗時,我在我的操作類中使用此邏輯。
沒有匹配你正在尋找的字符串。評論是否在格式化您的帖子時被解析出來? – 2010-03-31 17:41:00
嘗試檢查您的輸入字符串 – Roman 2010-03-31 17:44:49
您可以顯示代碼設置輸入值的位置嗎? – 2010-03-31 17:47:10