Solved

How to get this substring?

Posted on 2006-06-29
9
479 Views
Last Modified: 2008-02-26
"C:\ViaSafe\Channel/boaTest/BoaFromExtract/report/done/1151076810520.0@BoaFromExtract.boaTest.A6.txt.ExtractReport.pdf"

The above is a string which I want to get the "A6.txt" out of it, the substring after it ".ExtractReport.pdf" and the string before it "@BoaFromExtract.boaTest." will always be constant.  However, the A6.txt can varies in size as I can have A12312321.txt, B23424.txt ect......

I know this has to do with Substring manipulation and trimming my string but I can not seem to come up with a clean method to do it, please help.

Thanks.

btw I store the orignal string in a String array.
0
Comment
Question by:fylix0000
  • 5
  • 4
9 Comments
 
LVL 14

Accepted Solution

by:
hoomanv earned 500 total points
ID: 17012802
           Pattern p = Pattern.compile("BoaFromExtract\\.boaTest\\.(.+)\\.ExtractReport\\.pdf");
            Matcher m = p.matcher("C:\\ViaSafe\\Channel/boaTest/BoaFromExtract/report/done/1151076810520.0@BoaFromExtract.boaTest.A6.txt.ExtractReport.pdf");
            m.find();
            System.out.println(m.group(1));
0
 

Author Comment

by:fylix0000
ID: 17013041
Tried to run this but the compile method does not seem to work, I check for Patter.method in my IDE but could not see compile either.
0
 
LVL 14

Expert Comment

by:hoomanv
ID: 17013049
have you imported java.util.regex.* ?
0
 

Author Comment

by:fylix0000
ID: 17013183
I had import import java.util.regex.Matcher; only before
but eafter I put in import java.util.regex.*; then i still get the same error.

Focus on error gives me : The method compile(ClassGenerator, MethodGenerator) in the type Expression is not applicable for
 the arguments (String)


Sorry I am quite new to this Pattern so I am kind of clueless.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 14

Expert Comment

by:hoomanv
ID: 17013221
what is the exact phrase of compile error ?
0
 

Author Comment

by:fylix0000
ID: 17013237
Exception in thread "main" java.lang.Error: Unresolved compilation problems:
      The method compile(ClassGenerator, MethodGenerator) in the type Expression is not applicable for the arguments (String)
      The method matcher(String) is undefined for the type Pattern

      at name_string.main(name_string.java:11)
0
 
LVL 14

Expert Comment

by:hoomanv
ID: 17013242
try
java.util.regex.Pattern p = java.util.regex.Pattern.compile("BoaFromExtract\\.boaTest\\.(.+)\\.ExtractReport\\.pdf");
0
 

Author Comment

by:fylix0000
ID: 17013249
Actually , nevermind...somehow my IDE put in import com.sun.org.apache.xalan.internal.xsltc.compiler.Pattern;



will try again, as I took it out and looks good so far.
0
 

Author Comment

by:fylix0000
ID: 17013254
Thank you, worked like a charm :)
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Unable to start eclipse ? 17 133
Strange loading of website behaviour 3 32
JUnit 4 @Before and @BeforeClass differences 3 48
egit plugin on eclipse 8 40
An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now