*
The moose likes Java in General and the fly likes substring a string in the reverse direction Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "substring a string in the reverse direction" Watch "substring a string in the reverse direction" New topic
Author

substring a string in the reverse direction

JayaSiji Gopal
Ranch Hand

Joined: Sep 27, 2004
Posts: 303
I have a string 1099647.

I need to substring this string from 7 to 4. Can this be done?


SCJP 1.4, SCWCD 1.4<br /> <br />Thanks in advance!<br />Jayashree.
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
There's no single method call to do it, but you can just write a loop to append characters to a StringBuilder.


"I'm not back." - Bill Harding, Twister
Jeff Storey
Ranch Hand

Joined: Oct 09, 2006
Posts: 118
You can also do it as follows:



You may have to tweak your indices of 4 and 7 if this is not exactly what you want, but this should give you the idea.

Jeff
 
Consider Paul's rocket mass heater.
 
subject: substring a string in the reverse direction
 
Similar Threads
Date / Time problems
pet peeves 2
String index out of bound at index 0?! HELP!
subString
OOP-2: parsing strings