ios - [string lastPathComponent] 问题

标签 ios nsstring

我想从这样的字符串中提取文件名

C:\IBM\...\images\custom\fileName.png

但是

[string lastPathComponent];

给我整个字符串而不是 fileName.png。我在这里做错了什么?

最佳答案

我相信 lastPathComponent 根据正斜杠“/”拆分,您的路径只包含反斜杠“\”

您可以尝试替换反斜杠:

[path stringByReplacingOccurrencesOfString:@"\\" withString:@"/"].lastPathComponent;

关于ios - [string lastPathComponent] 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23506295/

相关文章:

iphone - 如何绘制只是一个圆圈的自定义 UIView - iPhone 应用程序

ios - 为什么仍然出现 "Could not cast value of type"错误?

ios - 如何在休息套件中解析此响应?

iphone - 对数组进行排序时忽略某些字符串

iphone - 添加到邮件正文时 NSString 丢失新行

iphone - NSString 如何去除常规\转义字符?

ios - 在 NSMutableArray 中访问 NSString

ios - 在 iOS 中使用 NSJSONSerialization 是否有数据限制?

iphone - 如何创建一个行为类似于 UIKeyboard (Numberpad) 的 UIButton 矩阵?

iOS:根据 UILabel 的大小找到正确的字体大小以适合其大小