function to get the file name of an URL

前端 未结 6 1831
时光说笑
时光说笑 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条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-01-30 05:39

    I haven't tried this yet, but it seems like you might be trying to do this the hard way. The iPhone libraries have the NSURL class, and I imagine that you could simply do:

    NSString *url = [NSURL URLWithString:@"http://www.google.com/a.pdf"];
    NSString *path = [url path];
    

    Definitely look for a built in function. The libraries have far more testing and will handle the edge cases better than anything you or I will write in an hour or two (generally speaking).

提交回复
热议问题