OC字符串实现路径合并

  • OC中使用字符串完成路径合并的操作
 1 /**
 2  *  路径合并案例
 3  *  stringByTrimmingCharactersInset:
 4  */
 5 #import <Foundation/Foundation.h>
 6 
 7 int main(int argc, const char * argv[]) {
 8     @autoreleasepool {
 9         
10         NSString *path=@"Users/apple/Desktop";//文件路径
11         NSString *file=@"test.html";//文件名
12         
13         //NSLog(@"%@",path stringByTrimmingCharactersInSet)//去除字符  如果有就去除 没有则不改变
14         //合并路径
15         NSString *filePath=[NSString stringWithFormat:@"/%@/%@",[path stringByTrimmingCharactersInSet: [NSCharacterSet characterSetWithCharactersInString:@"/" ]],file];
16         
17         NSLog(@"%@",filePath);//打印结果:/Users/apple/Desktop/test.html
18         
19         
20     }
21     return 0;
22 }

 

posted @ 2015-09-20 19:33  A+P=S  阅读(448)  评论(0编辑  收藏  举报