//"c:\\abc\\images\\button.dat".fileName(); 返回值:button
String.prototype.fileName = function(){
return this.substring(this.lastIndexOf("\\")+1,this.lastIndexOf("."));
}
//"c:\\abc\\images\\button.dat".fileType(); 返回值:dat
String.prototype.fileType = function(){
return this.substring(this.lastIndexOf(".")+1);
}
//"c:\\abc\\images\\button.dat".fileTypeValidate("jpg|gif|exe","|"); 返回值: false
String.prototype.fileTypeValidate = function(fileType,separator){
if(Object.isArray(fileType))
return new RegExp("^("+fileType.join("|")+")$","g").test(this.fileType());
else if (Object.isString(fileType) && Object.isString(separator))
return new RegExp("^("+(Object.isString(separator)?fileType.split(separator):fileType.split("|")).join("|")+")$","g").test(this.fileType());
else
return false;
}
//包装到一个属性中
String.prototype.FILE = {
//谁能把上面的这三个功能集成到这里
}
例如:
"c:\\abc\\images\\button.dat".FILE.fileName(); 返回值:button
"c:\\abc\\images\\button.dat".FILE.fileType(); 返回值:dat
"c:\\abc\\images\\button.dat".FILE.fileTypeValidate("jpg|gif|exe","|"); 返回值: false
各位帮忙看看吧。
String.prototype.fileName = function(){
return this.substring(this.lastIndexOf("\\")+1,this.lastIndexOf("."));
}
//"c:\\abc\\images\\button.dat".fileType(); 返回值:dat
String.prototype.fileType = function(){
return this.substring(this.lastIndexOf(".")+1);
}
//"c:\\abc\\images\\button.dat".fileTypeValidate("jpg|gif|exe","|"); 返回值: false
String.prototype.fileTypeValidate = function(fileType,separator){
if(Object.isArray(fileType))
return new RegExp("^("+fileType.join("|")+")$","g").test(this.fileType());
else if (Object.isString(fileType) && Object.isString(separator))
return new RegExp("^("+(Object.isString(separator)?fileType.split(separator):fileType.split("|")).join("|")+")$","g").test(this.fileType());
else
return false;
}
//包装到一个属性中
String.prototype.FILE = {
//谁能把上面的这三个功能集成到这里
}
例如:
"c:\\abc\\images\\button.dat".FILE.fileName(); 返回值:button
"c:\\abc\\images\\button.dat".FILE.fileType(); 返回值:dat
"c:\\abc\\images\\button.dat".FILE.fileTypeValidate("jpg|gif|exe","|"); 返回值: false
各位帮忙看看吧。
