<pre name="code" class="java">
//获取文件名,不带后缀
var file_name=file_path.replace(/(.*\/)*([^.]+).*/ig,"$2");
//获取文件后缀
1.var FileExt=file_path.replace(/.+\./,"");
2.var fileExtension = file_path.substring(file_path.lastIndexOf('.') + 1);
//截取文件后缀
var reg = /\.\w+$/;
var file_name = file_path.replace(reg,'');
<div> var postfix=file.substr(file.lastIndexOf(".")+1,file.length); </div>
java
public class StringDemo {
public static void main(String[] args) {
String str = "www.yiibai.com";
System.out.println(str);
// the end string to be checked
String endstr1 = ".com";
String endstr2 = ".org";
// checks that string str ends with given substring
boolean retval1 = str.endsWith(endstr1);
boolean retval2 = str.endsWith(endstr2);
// prints true if the string ends with given substring
System.out.println("ends with " + endstr1 + " ? " + retval1);
System.out.println("ends with " + endstr2 + " ? " + retval2);
}
}