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 Want to strip only part of a string Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Want to strip only part of a string" Watch "Want to strip only part of a string" New topic

Want to strip only part of a string

sue jacob

Joined: Oct 06, 2005
Posts: 9
i have string l_relatedMatterCode which has value something like this:

(00205EPOPP) - 3M Dyneon against E.I. du Pont

I want to strip only the value within the paranthesis and store it in another variable. I cannot do a substring bcos the length of the string within the paranthesis is not always 10.

can anybody help me with any function for this?...

Thankyou and appreciate your efforts in helping me on this.
[ October 21, 2005: Message edited by: Mark Spritzler ]
Makarand Parab
Ranch Hand

Joined: Dec 10, 2004
Posts: 121
Here it comes

public String getData()
String data = "(00205EPOPP) - 3M Dyneon against E.I. du Pont";
int pointer = data.lastIndexOf(")");
String finaldata = data.substring(1,pointer-1);
return finaldata;

Let me know if this works for you.

Makarand Parab
madhup narain
Ranch Hand

Joined: Dec 14, 2004
Posts: 148

i really dont understand your question however if you mean stripping data off brackets '()' then here is a solution for a start.

1) i assume that () occurs only once

class stripMe{
public static void main(String args[]){
String data="(00205EPOPP) - 3M Dyneon";
String newString="";
for (int i=0;i<data.length();i++){
if (data.charAt(i)=='('){

Money for nothing and Java for Free
Mark Spritzler

Joined: Feb 05, 2001
Posts: 17276

First, let's remove that "URGENT" from your thread topic. Thread that have topics with URGENT tend not to get replies. And doesn't improve your chances of getting an answer quicker.

What about the regex expression "(*)" or something like that. Then it is simple.

Perfect World Programming, LLC - iOS Apps
How to Ask Questions the Smart Way FAQ
sue jacob

Joined: Oct 06, 2005
Posts: 9
Thanks everybody for all your inputs!....

I tried Makarand's code and it worked except that i had to say
instead of

Thanks again!
I agree. Here's the link:
subject: Want to strip only part of a string
It's not a secret anymore!