下面是官方的说明:
源字符串
--->
结果字符串
“/tmp/scratch.tiff”
--->
“scratch.tiff”
“/tmp/scratch”
--->
“scratch”
“/tmp/”
--->
“tmp”
“scratch”
--->
“scratch”
“/”
--->
“/”
获取网络数据或者路径的文件名以及后缀
2012年02月10日 星期五 14:38
// 从路径中获得完整的文件名(带后缀)
exestr = [filePath lastPathComponent];
NSLog(@"%@",exestr);
// 获得文件名(不带后缀)
exestr = [exestr stringByDeletingPathExte
nsion];
原文地址:lastPathComponent的功能作者:青竹居士下面是官方的说明:源字符串 ---> 结果字符串“/tmp/scratch.tiff” ---> “scratch.tiff”“/tmp/scratch” ---> “scratch”“/tmp/” ---> “tmp”“scratch” --->
常用路径处理方法:
+ (NSString *)
path
With
Component
sNSArray *)
component
s
根据
component
s中的元素来构建路径.
- (NSArray *)
path
Component
s
解析路径,返回构成路径的各个部分.
- (NSString *)last
Path
Component
提取路径中的最后一个组成部分
- (NSString *)
path
Ext
我们用字符串来表达文件的位置(路径)。这会在我们处理文件是经常碰到,也就是说,存储文件路径的NSString字符串对象。
Cocoa中文件路径的字符串表示是标准的,NSString也提供了一系列的method供我们处理文件路径字符串。这些method帮助我们把相对路径替换为绝对路径,解析符号链接,抽取路径成分到新的字符串中,以及处理文件扩展名。
现在我们都知道Mac OS X是建筑在U
源字符串 ---> 结果字符串
“/tmp/scratch.tiff” ---> “scratch.tiff”
“/tmp/scratch” ---> “scratch”
“/tmp/” ---> “tmp”
“scratch” --->
常用路径处理方法:
+ (NSString *)
path
With
Component
sNSArray *)
component
s
根据
component
s中的元素来构建路径.
- (NSArray *)
path
Component
s
解析路径,返回构成路径的各个部分.
- (NSString *)last
Path
Component
提取路径中的最后一
swift5优秀打印函数自定义
func LJLog<T>(message: T,file: String = #file,funcName: String=#function,lineNum: Int=#line){
let file2 = ( file as NSString).last
Path
Component
debugPrint("\(file2):[\(funcName)](\(lineNum))-\(message)")
放在 AppDelegate.swif
做测试一般只需要创建 "OS X" 的 "Command Line Tool" 即可。
NSString * urlString = @"https://www.baidu.com/img/2016_6_9logo_e5230b7f39f078d288a313971a7fea56.gif";
1、
path
Component
NSURL
An object representing the location of a resource that bridges to URL; use NSURL when you need reference semantics or other Foundation-specific behavior.
--表征桥接到URL的资源位置的对象;当您需要引用语义或其他特定于Foundation的行为时,请使用NSURL。
--是一个对象,有自己的行为的,而不是单纯...
该类苹果在
iOS
7中添加,它(NSURL
Component
s)可以方便的把 URL 地址分解成多个部分;
其中, URL(Uniform Resource Locator)地址用于描述一个网络上的资源,基本格式如下:
schema://host[:port#]/
path
/.../[?query-string][#anchor]
schema:指定低层使用的协议,例如 http https