首页 > 学院 > 开发设计 > 正文

文件路径类 字符串的各种截取方式,包括截取到文件名

2019-11-09 15:29:11
字体:
来源:转载
供稿:网友

NSString* index=@"/Users/1.zip";

对路径进行截取的9种操作

    NSLog(@"1=%@",[index lastPathComponent]);

对应结果1=1.zip

    NSLog(@"2=%@",[index stringByDeletingLastPathComponent]);

对应结果 :去掉文件名2=   /Users/

    NSLog(@"3=%@",[index pathExtension]);

对应结果 :得到文件名后缀: 3=zip

    NSLog(@"4=%@",[index stringByDeletingPathExtension]);

对应结果 :除去文件的后缀   4=/Users/1

    NSLog(@"5=%@",[[index lastPathComponentstringByDeletingPathExtension]);

对应结果 :取文件名,不带后缀的: 5= 1


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表