• Post Reply Bookmark Topic Watch Topic
  • New Topic

java.lang.StringIndexOutOfBoundsException: String index out of range: -1  RSS feed

 
Ranch Hand
Posts: 833
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,



Here is stackTrace:


Please advise

Thanks in anticipation
 
Farakh khan
Ranch Hand
Posts: 833
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Farakh khan wrote:Hello,



I tried as:


By the way this regex is also working fine


Best regards
 
Marshal
Posts: 56610
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are not finding the space anywhere in the String, then you are looking for the space which you haven't found, then you are trying to find a substring ending at an index which doesn't exist, and then the String object complains it can't do what you want and throws that Exception.
Please explain what the second regular expression does.
 
Farakh khan
Ranch Hand
Posts: 833
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The second regex is finding the last word and remove/drop it
 
Campbell Ritchie
Marshal
Posts: 56610
172
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So you don't want the last part? You only want the first part? What is wrong withPlease confirm that the space you are seeking is an ordinary space ((char)0x0020). That technique will not work of you have something like non‑breaking space ((char)0x00a0).
 
Farakh khan
Ranch Hand
Posts: 833
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
great!!

Thanks for your favorable tips.
 
Campbell Ritchie
Marshal
Posts: 56610
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!