Solved

How to get this substring?

Posted on 2006-06-29
9
465 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
Comment Utility
           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
Comment Utility
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
Comment Utility
have you imported java.util.regex.* ?
0
 

Author Comment

by:fylix0000
Comment Utility
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 14

Expert Comment

by:hoomanv
Comment Utility
what is the exact phrase of compile error ?
0
 

Author Comment

by:fylix0000
Comment Utility
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
Comment Utility
try
java.util.regex.Pattern p = java.util.regex.Pattern.compile("BoaFromExtract\\.boaTest\\.(.+)\\.ExtractReport\\.pdf");
0
 

Author Comment

by:fylix0000
Comment Utility
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
Comment Utility
Thank you, worked like a charm :)
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Suggested Solutions

For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

762 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

12 Experts available now in Live!

Get 1:1 Help Now