iOS 从url中获取文件名以及后缀
iOS 2020-03-28 16:08:32

示例地址:

NSString* index=@"/var/mobile/Containers/Data/Application/45471D33-E611-499D-AFA1-856880F47549/Documents/1543976290.wav";

 

C/C++ Code复制内容到剪贴板
  1. NSLog(@"%@",[index lastPathComponent]);  
  2. 输出:1543976290.wav  
  3.   
  4. NSLog(@"%@",[index stringByDeletingLastPathComponent]);  
  5. 输出:/var/mobile/Containers/Data/Application/45471D33-E611-499D-AFA1-856880F47549/Documents  
  6.   
  7. NSLog(@"%@",[index pathExtension]);  
  8. 输出:wav  
  9.   
  10. NSLog(@"%@",[index stringByDeletingPathExtension]);  
  11. 输出:/var/mobile/Containers/Data/Application/45471D33-E611-499D-AFA1-856880F47549/Documents/1543976290  
  12.   
  13. NSLog(@"%@",[index stringByAbbreviatingWithTildeInPath]);  
  14. 输出:~/Documents/1543976290.wav  
  15.   
  16. NSLog(@"%@",[index stringByExpandingTildeInPath]);  
  17. 输出:/var/mobile/Containers/Data/Application/45471D33-E611-499D-AFA1-856880F47549/Documents/1543976290.wav  
  18.   
  19. NSLog(@"%@",[index stringByStandardizingPath]);  
  20. 输出:/var/mobile/Containers/Data/Application/45471D33-E611-499D-AFA1-856880F47549/Documents/1543976290.wav  
  21.   
  22. NSLog(@"%@",[index stringByResolvingSymlinksInPath]);  
  23. 输出:/var/mobile/Containers/Data/Application/45471D33-E611-499D-AFA1-856880F47549/Documents/1543976290.wav  
  24.   
  25. NSLog(@"%@",[[index lastPathComponent] stringByDeletingPathExtension]);  
  26. 输出:1543976290  

 

 

本文来自于:https://www.jianshu.com/p/5a67094c35f2

Powered by yoyo苏ICP备15045725号-1