-3

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)?

Ori Marko
  • 56,308
  • 23
  • 131
  • 233
jeja
  • 52
  • 11

2 Answers2

0

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);

 }

}

0
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;

}

jeja
  • 52
  • 11