This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell 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


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: 17250
    
    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!
 
GeeCON Prague 2014
 
subject: Want to strip only part of a string