File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes Playing with String Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Playing with String" Watch "Playing with String" New topic

Playing with String

Steve Bradley

Joined: Jun 09, 2004
Posts: 15
Hi gang,

Here's one I could use some help with...

I would like to create a new String object which is the value of (char's between parameters) within an existing String object so that....

I've been playing with String.toCharArray and StringBuffer objects...

What is the best route to get from String a to String b?
Paul Sturrock

Joined: Apr 14, 2004
Posts: 10336

Have a look at the java.util.regex package.

JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Matthew Taylor

Joined: Jun 13, 2004
Posts: 110
If you don't want to mess with a StringBuffer, you can use the indexOf() and substring() methods of String. Like this:

substring(int,int) takes the first and last index of the string and creates a new substring of it. So if you find the indexOf() the "(" and ")" and pass those ints to substring(int,int), you'll create the proper substring. But you have to +1 to the first index so you won't include the "(".


Grails Consultant
I agree. Here's the link:
subject: Playing with String
It's not a secret anymore!