Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Want to strip only part of a string

 
sue jacob
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • 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 ]
 
Makarand Parab
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
  • 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
 
madhup narain
Ranch Hand
Posts: 148
  • Mark post as helpful
  • send pies
  • 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);
}
}
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • 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
  • 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!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic