AlaSQL / alasql

AlaSQL.js - JavaScript SQL database for browser and Node.js. Handles both traditional relational tables and nested JSON data (NoSQL). Export, store, and import data from localStorage, IndexedDB, or Excel.
http://alasql.org
MIT License
7.01k stars 653 forks source link

Get file extension from file name. #602

Closed MarioVanDenEijnde closed 8 years ago

MarioVanDenEijnde commented 8 years ago

Hello ALASQL team,

I have got a new challenge: I have got a field value like:

"Name":"W-LB-FD-3.3 testmethode rotatoire wrijving lab eigenmethode.doc"

And I need:

"fileName":"W-LB-FD-3.3 testmethode rotatoire wrijving lab eigenmethode", "fileType":"doc""

Any idea? Kind regards, Mario

mathiasrw commented 8 years ago

Make a user defined function

alasql.fn.fileName = function(name) {
    var all = name.split('.')
    all.pop();
    return all.join('.');
};

alasql.fn.fileType = function(name) {
    return name.split('.').pop();
};

So you can

select fileName(name) as fileName, fileType(name) as fileType from ?

Code not tested