NSString截取文件名(很笨的方法)

对NSString的操作不熟悉,目前采用以下方法取得路径中的文件名以及文件夹路径

    NSString* test=[[NSString alloc]initWithFormat:@"D:\\compile\\20140523155024344.EC0"];
    NSArray *array = [test componentsSeparatedByString:@"\\"];
    NSLog(@"filename is %@",[array objectAtIndex:array.count-1]);
    NSLog(@"path is %@",[test stringByReplacingOccurrencesOfString:[array objectAtIndex:array.count-1] withString:@""]);

  方法很笨,大家见谅,有好的也可以留言,谢谢

posted @ 2014-05-23 16:56  dongweiq  阅读(616)  评论(0编辑  收藏  举报