Computer Science Canada PLEASEEEEEEHELP MEEEEE ITS DUE TMR String index out of range: -1 |
Author: | worthless [ Tue Mar 31, 2015 3:51 pm ] | ||||
Post subject: | PLEASEEEEEEHELP MEEEEE ITS DUE TMR String index out of range: -1 | ||||
AND I GOT THIS
Mod Edit: Please syntax="java" or code BBcode tags to wrap your code and stuff. |
Author: | Zren [ Tue Mar 31, 2015 5:00 pm ] | ||
Post subject: | RE:PLEASEEEEEEHELP MEEEEE ITS DUE TMR String index out of range: -1 | ||
String.indexOf() will return -1 if it can't find the string you supply it. http://docs.oracle.com/javase/6/docs/api/java/lang/String.html#indexOf(java.lang.String) Try debugging what character you're trying to find. Use System.out.println() to print the values of your variables. Example:
I'm guessing you forgot about the newline character (\n) or the whitespace character. http://www.asciitable.com/index/asciifull.gif |