A friendly place for programming greenhorns!
Big Moose Saloon
Register / Login
Java in General
substring a string in the reverse direction
Joined: Sep 27, 2004
Jan 26, 2007 10:15:00
I have a
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.
Joined: Jan 30, 2000
Jan 26, 2007 12:04:00
There's no single method call to do it, but you can just write a loop to append characters to a
"I'm not back." - Bill Harding,
Joined: Oct 09, 2006
Jan 27, 2007 16:11:00
You can also do it as follows:
String s = new String("abcdefgh"); String sReverse = new StringBuilder(s.substring(4,7)).reverse().toString();
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.
I agree. Here's the link:
subject: substring a string in the reverse direction
OOP-2: parsing strings
pet peeves 2
Date / Time problems
String index out of bound at index 0?! HELP!
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter
| Powered by
Copyright © 1998-2014