Use lastIndexOf() and substr():
function getFileExtension(name)
{
int found = name.lastIndexOf('.') + 1;
return (found > 0 ? name.substr(found) : "");
}
Note that this implementation returns an empty string if the filename doesn't contain any period character (i.e. has no extension). Implementations based on split() sometimes return the full filename in that case.