Check and make sure the value is not -1
if ( wordEndLoc == -1 ){
// most likely the user entered a single word or just pressed the enter button (the s1 string is empty).
//Deal with each...
Type: Posts; User: copeg
Check and make sure the value is not -1
if ( wordEndLoc == -1 ){
// most likely the user entered a single word or just pressed the enter button (the s1 string is empty).
//Deal with each...
indexOf returns -1 if the search item was not found, so if what a space isn't found you will see this exception when your code continues to try and parse the string.