美文网首页
NSSting 对字符串路径的操作

NSSting 对字符串路径的操作

作者: kindom_0129 | 来源:发表于2017-02-22 18:25 被阅读0次
    void Path(){
        NSArray *arry=[[[NSArray alloc] initWithObjects:@"abc",@"mike",@"gan", nil] autorelease ];
        NSString *str=  [NSString pathWithComponents:arry];//将NSArray集合拼成一个路径
        NSLog(@"%@",str);
        NSString *str1=@"abc/dc/ed.txt";
        NSLog(@"%@",[str1 pathComponents]);//把路径转换成NSSArray集合。
         
        NSLog(@"%i",[str1 isAbsolutePath]);//是否是绝对路径用/开头判断
        NSLog(@"%@",[str1 lastPathComponent]);//获得最后一个文件
        NSLog(@"%@",[str1  stringByDeletingLastPathComponent]);//删除最后一个目录。
        NSLog(@"%@",[str1 stringByAppendingFormat:@".txt.%i",12]);//追加文件名
        NSLog(@"%@",[[str1 lastPathComponent] stringByDeletingPathExtension]);//获取最后一个文件,并去除扩展名
    }
    

    输出

    2013-04-23 05:32:38.130 字符串03[1105:303] abc/mike/gan
    2013-04-23 05:32:38.136 字符串03[1105:303] (
        abc,
        dc,
        "ed.txt"
    )
    2013-04-23 05:32:38.140 字符串03[1105:303] 0
    2013-04-23 05:32:38.141 字符串03[1105:303] ed.txt
    2013-04-23 05:32:38.143 字符串03[1105:303] abc/dc
    2013-04-23 05:32:38.144 字符串03[1105:303] abc/dc/ed.txt.txt.12
    2013-04-23 05:32:38.145 字符串03[1105:303] ed
    

    相关文章

      网友评论

          本文标题:NSSting 对字符串路径的操作

          本文链接:https://www.haomeiwen.com/subject/fvvmwttx.html