944,188 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Unsolved
  • Views: 426
  • Java RSS
Nov 5th, 2009
0

Reasigning variables

Expand Post »
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
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
skiplatte is offline Offline
10 posts
since Oct 2009
Nov 5th, 2009
0
Re: Reasigning variables
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..
Moderator
Reputation Points: 1471
Solved Threads: 490
Industrious Poster
masijade is offline Offline
4,043 posts
since Feb 2006
Nov 5th, 2009
1
Re: Reasigning variables
Click to Expand / Collapse  Quote originally posted by masijade ...
... I don't know how substring reacts if the end index is smaller than the start index..
API doc states:

Quote ...
Throws: IndexOutOfBoundsException - if the beginIndex is negative, or endIndex is larger than the length of this String object, or beginIndex is larger than endIndex.
Featured Poster
Reputation Points: 1939
Solved Threads: 954
Posting Expert
JamesCherrill is online now Online
5,812 posts
since Apr 2008
Nov 5th, 2009
0
Re: Reasigning variables
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. ;-)
Moderator
Reputation Points: 1471
Solved Threads: 490
Industrious Poster
masijade is offline Offline
4,043 posts
since Feb 2006

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: Question about tables
Next Thread in Java Forum Timeline: Java hang man, help please.





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC