dipgirl
dipgirl

Reputation: 690

How to get the specific word in whole sentences

I am using ionic 4. I want to condition base on the extension. For example file:///storage/emulated/0/Document/myFile.zip and file:///storage/emulated/0/Document/file.pdf. I want to check it is either the zip file or pdf file. I want to get the extension from the path. my code should be like this:

if(extension == "pdf")
{
}
else 
{
}

My problem is how to get the 'pdf' or 'zip' from the path. Anyone can help me?

Upvotes: 0

Views: 31

Answers (1)

Shailesh Bhokare
Shailesh Bhokare

Reputation: 592

To get extension from the path just refer below code:

var path = 'file:///storage/emulated/0/Document/myFile.zip'
var extension = path.substring(path.lastIndexOf('.') + 1)

you can apply conditions of extension variable.

Happy Coding :-)

Upvotes: 1

Related Questions