• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Want to strip only part of a string

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 148
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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);
}
}
 
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
sue jacob
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
reply
    Bookmark Topic Watch Topic
  • New Topic