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

StringBuffer problem

Andrew Hartman

Joined: Mar 18, 2004
Posts: 16
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 ')'.

Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
Another way
Chengwei Lee
Ranch Hand

Joined: Apr 02, 2004
Posts: 884
Originally posted by Michael Dunn:
Another way

This would only work if you're using 1.4 and above.

SCJP 1.4 * SCWCD 1.4 * SCBCD 1.3 * SCJA 1.0 * TOGAF 8
Richard Bradford
Ranch Hand

Joined: Apr 20, 2004
Posts: 48
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 );
I agree. Here's the link:
subject: StringBuffer problem
It's not a secret anymore!