This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
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 OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP 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
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: substring a string in the reverse direction