Whenever I want to parse the string "0" in Java to 0 (int) it throws a InvalidInt-Error.
However strings like "1", "2" etc. work.

UPDATE: Other numbers don't work as well.

I'm fetching the HTML source code of a PHP-File from my web page and this web page only displays one number.

Code:

String[] result = sourceCode.trim().split("<br>");
for (int i = 0; i < result.length; i++)
{
    result[i] = result[i].trim().replace("\n", "").replace("\r", "");
}

    if (Integer.parseInt(result[0]) > 0) 
    {
         //Do Something
    }

Error Message

有帮助吗?

解决方案

With the information provided in the comments below the question, it turns out that you have the Unicode Character 'ZERO WIDTH NO-BREAK SPACE' (U+FEFF) repeatedly at the beginning of your String. You can do the following to remove it:

final String ZERO_WIDTH_NO_BREAK_SPACE = "\uFEFF";
String good = result[0].replace(ZERO_WIDTH_NO_BREAK_SPACE, "");

Also, there is one TAB hidden inbetween all those characters. Get rid of it with

good = good.replaceAll("\\s+", "");
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top