oc-Foundation框架-NSString-常用方法-路径相关

NSMutableArray *arry=[NSMutableArray array];//可变数组
    [arry addObject:@"Users"];
    [arry addObject:@"liysng"];
    [arry addObject:@"desktop"];
    NSString *path=[NSString pathWithComponents:arry];
    NSLog(@"%@",path);//将数组里面的内容拼接城路径
    NSArray *arry1=[path pathComponents];//将路径分解
    for(NSString *a in arry1){
        NSLog(@"%@",a);
    }

 

 NSString *path=@"/users/liyang/desktop/liyang.txt";
   NSLog(@"%i",[path isAbsolutePath]);//判断是否为结对路径,这个判断很笨拙,它就是检测是否以“/”开头

 

NSString *path=@"/users/liyang/desktop/liyang.txt";
   NSLog(@"%@",[path lastPathComponent]);//路径分割的最后一个元素这里返回的是liyang.txt

 

NSString *path=@"/users/liyang/desktop/liyang.txt";
   NSLog(@"%@",[path stringByDeletingLastPathComponent]);//
删除最后一个路径元素,随后是没有"/"

 

   NSString *path=@"/users/liyang/desktop/liyang.txt";
   NSLog(@"%@",[path stringByAppendingPathComponent:@"oo"]);//和上面的相反,这个是拼接一个路径

 

posted @ 2014-03-20 22:58  离子  阅读(190)  评论(0编辑  收藏  举报