Reasigning variables

Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Oct 2009
Posts: 10
Reputation: skiplatte is an unknown quantity at this point 
Solved Threads: 0
skiplatte skiplatte is offline Offline
Newbie Poster

Reasigning variables

 
0
  #1
Nov 5th, 2009
I'm getting StringIndexOutOfBoundsException when I try to reasign the value of a variable.

protString = protString.substring(newRPos+1, input.length());
I understand that this is something I would rather not do... but as I don't know the index of newRPos I can't think of another way to iterate.

Thanks
Last edited by peter_budo; Nov 5th, 2009 at 12:14 pm. Reason: Correcting code tags
Reply With Quote Quick reply to this message  
Join Date: Feb 2006
Posts: 2,441
Reputation: masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of 
Solved Threads: 260
Moderator
masijade's Avatar
masijade masijade is online now Online
Nearly a Posting Maven
 
0
  #2
Nov 5th, 2009
Then also check with if (newRPos < protString.length). Also, is there any guarantee that input.length() is going to be larger than newRPos, as both of those are indexes (i.e. a start index and an end index) not a start and length, and I don't know how substring reacts if the end index is smaller than the start index..
Java Programmer and Sun Systems Administrator

----------------------------------------------

Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 989
Reputation: JamesCherrill is just really nice JamesCherrill is just really nice JamesCherrill is just really nice JamesCherrill is just really nice JamesCherrill is just really nice 
Solved Threads: 146
JamesCherrill JamesCherrill is offline Offline
Posting Shark
 
1
  #3
Nov 5th, 2009
Originally Posted by masijade View Post
... I don't know how substring reacts if the end index is smaller than the start index..
API doc states:

Throws: IndexOutOfBoundsException - if the beginIndex is negative, or endIndex is larger than the length of this String object, or beginIndex is larger than endIndex.
Reply With Quote Quick reply to this message  
Join Date: Feb 2006
Posts: 2,441
Reputation: masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of 
Solved Threads: 260
Moderator
masijade's Avatar
masijade masijade is online now Online
Nearly a Posting Maven
 
0
  #4
Nov 5th, 2009
Originally Posted by JamesCherrill View Post
API doc states:
Thanks. That was just me being too lazy to look it up myself, and hoping the OP would figure out to do that. ;-)
Java Programmer and Sun Systems Administrator

----------------------------------------------

Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
Reply With Quote Quick reply to this message  
Reply

Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC