This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
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 Murach's Java Servlets and JSP this week in the Servlets 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
Author

Want to strip only part of a string

sue jacob
Greenhorn

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.

Regards
Makarand Parab
madhup narain
Ranch Hand

Joined: Dec 14, 2004
Posts: 148
hi,

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

assumption--
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)=='('){
i++;
while(data.charAt(i)!=')'){
newString=newString+data.charAt(i);
i++;
}
}
}
System.out.println(newString);
}
}


Money for nothing and Java for Free
SCJP, SCWCD
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17249
    
    6

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 - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
sue jacob
Greenhorn

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
data.substring(1,pointer);
instead of
data.substring(1,pointer-1);

Thanks again!
 
Don't get me started about those stupid light bulbs.
 
subject: Want to strip only part of a string
 
Similar Threads
Need Help outputting double quotes
how to format text from 01/12/1999 to 01121999 ?
Regular Expressions
Dumping A string value???
How to extract a substring of a string?