Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hello.
I have one
unstructured
txt file with several occurrences that I want to extract and save to another file.For example, let's say that we have this text
: "I want to get file1.pdf and file2.pdf" - All I need is to have all the
occurrences that contains *.pdf" and save them in to a new file row by row like this:file1.pdf
file2.pdf
Is this possible?
Thank you so much!
Hi
Read the file as a string using tFileInputRaw, and then extract the file name from the string using regex, for details, see below:
MyRoutine codes:
package routines;
import java.util.regex.*;
import java.util.Calendar;
import java.util.Date;
public class MyRoutine {
static Pattern pattern=Pattern.compile("\\s[\\d\\w]+\\.pdf");
static Matcher matcher=null;
static String result="";
public static String ExtractFileName(String inputData) {
matcher=pattern.matcher(inputData);
while (matcher.find()) {
if (result.equals("")){
result=matcher.group();
}else{
result=result+","+matcher.group();
}
}
return result;
}
}
Hope it helps you!
Regards
Shong
Hi
Read the file as a string using tFileInputRaw, and then extract the file name from the string using regex, for details, see below:
MyRoutine codes:
package routines;
import java.util.regex.*;
import java.util.Calendar;
import java.util.Date;
public class MyRoutine {
static Pattern pattern=Pattern.compile("\\s[\\d\\w]+\\.pdf");
static Matcher matcher=null;
static String result="";
public static String ExtractFileName(String inputData) {
matcher=pattern.matcher(inputData);
while (matcher.find()) {
if (result.equals("")){
result=matcher.group();
}else{
result=result+","+matcher.group();
}
}
return result;
}
}
Hope it helps you!
Regards
Shong
Works!
Thank you so much