function to get the file name of an URL

前端 未结 6 1837
时光说笑
时光说笑 2021-01-30 05:23

I have some source code to get the file name of an url

for example:

http://www.google.com/a.pdf

I hope to get a.pdf

because the way to join 2 NSS

6条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-01-30 05:48

    The following line does the job if url is a NSString:

    NSString *filename = [url lastPathComponent];
    

    If url is a NSURL, then the following does the job:

    NSString *filename = [[url path] lastPathComponent];
    

提交回复
热议问题