My variable is:
var filePath = "C:\\Libraries\\Documents\\123_test\\Report_11071991";
I have a variable as above in javascript
Can I have some code to get only the numeric part(11071991
) from the last folder(Report_11071991
)?
My variable is:
var filePath = "C:\\Libraries\\Documents\\123_test\\Report_11071991";
I have a variable as above in javascript
Can I have some code to get only the numeric part(11071991
) from the last folder(Report_11071991
)?
This is bad example, because no proffessional code. Please read articles for regular expression Pattern, Matcher.
public class Test {
public static void main(String[] args) {
String filePath="C:\\Libraries\\Documents\\123_test\\Report_11071991";
String[] lines = filePath.split("_");
filePath=lines[lines.length-1];
System.out.println(filePath);
}
}
var filePath = "C:\\Libraries\\Documents\\123_test\\Report_11071999";
var lastFolderName = filePath.substring(filePath.lastIndexOf("\")); //Report_11071999
if (lastFolderName.indexOf("Report_") >= 0) {
var out = lastFolderName.substring(7);
}
else {
out = lastFolderName;
}