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:@""]);

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

原文地址:https://www.cnblogs.com/dongweiq/p/3748084.html