Problem:
You are dealing with files and want a quick way to extract the files extension.
Solution:
A simple function that will return back you to the extension of any file with or without a full path reference preceding it is this:
function getFileExtention(str:String):String{NOTE: This will not account for URLs that have GET parameters on the end of them. To do this, Google search getting file extension using regexp or regular expressions.
return str.substring(str.lastIndexOf(".") + 1, str.length);
}
I hope this helps someone who is looking for a quick solution online. Good luck.
No comments:
Post a Comment