问题描述
我正在尝试读取来自使用Angular 6中的Web服务的服务器的文件扩展名.
I am trying to read the extension of a file which is coming from a server using web services in Angular 6.
我能够使用 filename.split('.').pop();
方法并使用 filename.slice((filename.lastIndexOf(.")-1>> 0)+ 2);
方法.
I am able to read the extensions of the file like myFile.png
using filename.split('.').pop();
method and using filename.slice((filename.lastIndexOf(".") - 1 >>> 0) + 2);
method.
但是我的问题是来自服务器的文件链接的长度非常长,并且它是可下载的链接,因此我们可以从该链接下载实际文件.
but my problem is the file link that is coming from the server is very long in length and it is a downloadable link so that from that link we can download the actual file.
在上面的链接中,我想读取文件的扩展名,该文件位于(?)
运算符之前.并且运算符(?)
在链接中只出现一次.这样我就可以确定文件的扩展名恰好位于(?)
运算符之前.
In the above link, I want to read the extension of the file which is just before the (?)
operator. and the operator(?)
is coming only once in the link. so that I can identified that the extension of the file is placed just before the (?)
operator.
任何人都可以使用Angular 6帮助获取文件扩展名.
can anyone help to get the extension of the file using Angular 6.
推荐答案
您所说的?
仅会出现一次,因此可以用?
拆分,然后选择第一个元素并再次用.
拆分并获取最后一个元素.
As you said ?
will come only once so can split with ?
and then select first element and again split with .
and get last element.
filename.split('?')[0].split('.').pop();
这篇关于在Angular 6中读取文件扩展名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!