I am using shared server with a php script that sends a number to my application. The server like to mess with me by 开发者_运维知识库adding an invisible ' to that number. I've been trying for around 6 hours fix this but there is no way for me to access the '. As soon as I convert the number(string form) to a real number it give an error that say the number looks like this: '200. You can never see the ' in logcat, only if the error occurs. If I log the string's length, it counts one more character than there should be. It works when I test it localy on my computer but when I upload it to the shared server it adds the '. Do anyone know why this is happening? Also is there any method to convert a string with a ' in it to a number without using any string manipulation methods since there is no way to access the ' ?
Try trimming the string before converting:
String number = dataFromServer.trim();
Integer.parseInt(number);
Are you sure the invisible thing is the quote character? It may be that the code that generates the error message attempts to put quotes around the string, but that there is something after the digits that eats the closing quote when displayed. (For example, a leading UTF-16 surrogate codepoint, or a U+0000?). Try to log out the numerical code units in the string you receive one by one.
Isn't your php script file encoded in "UTF-8 with BOM"? If yes try "UTF-8 without BOM", since it's a nasty-sometimes-invisible caracter that gets added at the beginning of the file and "sometimes" gets interpreted by the server.
精彩评论