Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Playing with String

 
Steve Bradley
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have a look at the java.util.regex package.
 
Matthew Taylor
Rancher
Posts: 110
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 "(".

HTH
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic