• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

StringBuffer problem

 
Andrew Hartman
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, I'm trying to basically strip a string and only want the content inbetween the () (excluding the brackets). I have posted the code so far, but I'm now a little stuck.
What I was trying to do was, using a boolean append to the StringBuffer when it meets the character '(' and stop when it meets an ')'.


Thanks
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Another way
 
Chengwei Lee
Ranch Hand
Posts: 884
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Michael Dunn:
Another way

This would only work if you're using 1.4 and above.
 
Richard Bradford
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The following should do what you ask.
String input = "TABLE1(string,contains,some,words)";
int start = input.indexOf( '(' );
int end = intput.indexOf( ')' );
String s = input.substring( start+1, end );
System.out.println( s );
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic