如何从文档目录中提取路径组件直到我的文件名? [英] How to extract a path components from documents directory till my file name?
本文介绍了如何从文档目录中提取路径组件直到我的文件名?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在我的iPhone应用程式中,
我要提取路径元件....
/ Users / priyadarshanjoshi / Library / Application Support / iPhone Simulator / 5.0 / Applications / A2CD9285-62E9-4447-9945-5D8CE090FB3A / Documents / Wine_12.png
我要提取
Wine_12.png
我正在编写此代码...
$ bNSString * relativePathImage1 = @;
BOOL append = NO;
for(NSString * get in [imagePath pathComponents])
{
if([get isEqualToString:@Documents])
{
append = YES;
}
if(append == YES)
{
relativePathImage1 = [relativePathImage1 stringByAppendingPathComponent:get];
}
}
NSLog(@relativePathImage1%@,relativePathImage1);
解决方案为什么不帮助下面的函数?它将导致在一个数组中的2个字符串,在文档和after文档之前。然后可以使用字符串后的文档和附加文档/在相同的和使用它。
[strPath componentsSeparatedByString:@Document]
In my iPhone Application,
I want to extract a path components....
/Users/priyadarshanjoshi/Library/Application Support/iPhone Simulator/5.0/Applications/A2CD9285-62E9-4447-9945-5D8CE090FB3A/Documents/Wine_12.png
I want to extract
/Documents/Wine_12.png
I am writing this code...
Is there any easier way to do the same?
NSString *relativePathImage1=@""; BOOL append=NO; for(NSString *get in [imagePath pathComponents]) { if([get isEqualToString:@"Documents"]) { append=YES; } if(append==YES) { relativePathImage1=[relativePathImage1 stringByAppendingPathComponent:get]; } } NSLog(@"relativePathImage1 %@",relativePathImage1);
解决方案why don't you take help of below function? It would result into 2 strings in an array,before document and after document. Yu can then use the string after document and append document/ in the same and use it.
[strPath componentsSeparatedByString:@"Document"]
这篇关于如何从文档目录中提取路径组件直到我的文件名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文