解析HTML時,每當我有'>'char
時,我需要檢查它後面是否有數字。該號碼可以是1位,2位或3位數字。從Java中的HTML字符串解析數字
該代碼似乎沒問題,但我總是得到一個StringIndexOutOfBoundException
。
代碼:
while (matches < 19)
{
more = dataInHtml.indexOf(">",index);
nextOne = dataInHtml.charAt(more + 1);
nextTwo = dataInHtml.charAt(more + 2);
nextThree = dataInHtml.charAt(more + 3);
if (Character.isDigit(nextOne)) digitOne = true;
if (Character.isDigit(nextTwo)) digitTwo = true;
if (Character.isDigit(nextThree)) digitThree = true;
if (digitThree)
{
data[matches] = dataInHtml.substring(more + 1, 3);
matches++;
digitThree = false;
digitTwo = false;
digitOne = false;
index = more + 3;
itWasADigit = true;
}
if (digitTwo)
{
data[matches] = dataInHtml.substring(more + 1, 2);
matches++;
digitTwo = false;
digitOne = false;
index = more + 2;
itWasADigit = true;
}
if (digitOne)
{
data[matches] = dataInHtml.substring(more + 1, 1);
matches++;
digitOne = false;
index = more + 1;
itWasADigit = true;
}
if (!(itWasADigit))
{
index = more + 1;
itWasADigit = false;
}
}
將字符轉換爲ASCII並比較值 – orangegoat 2013-02-08 15:45:12
哪一行正在執行StringIndexOutOfBoundException? – 2013-02-08 15:46:26
data [matches] = dataInHtml.substring(more + 1,2); – Alpan67 2013-02-08 15:48:31