1

我是 iphone 新手。我怀疑我的音频文件的路径位于资源文件夹的目录中,该路径是

/Users/Chary/Library/Application Support/iPhone Simulator/5.0/Applications/B02404E5-52DC-49B6-8DBB-C9946E4331AF/BiblePlayer.app/raj/1.mp3

我的问题是如何从整个路径中检索字符串“1.mp3”?

4

3 回答 3

4
NSString *fullPath = @"…";
NSString *fileName = [fullPath lastPathComponent];
于 2012-05-24T07:27:43.407 回答
1
NSString *allString = @"/Users/Chary/Library/Application Support/iPhone Simulator/5.0/Applications/B02404E5-52DC-49B6-8DBB-C9946E4331AF/BiblePlayer.app/raj/1.mp3"

int slashPosition = [allString rangeOfString:@"/" options:NSBackwardsSearch].location;
    NSString *function = [allString substringFromIndexslashPosition + 1];

这将为您提供最后一个斜杠后的文件路径

于 2012-05-24T07:28:23.657 回答
1

试试看:-

NSString *yourPath = @"/Users/Chary/Library/Application Support/iPhone Simulator/5.0/Applications/B02404E5-52DC-49B6-8DBB-C9946E4331AF/BiblePlayer.app/raj/1.mp3";
NSString *fileName = [yourPath lastPathComponent];

它可能会帮助你谢谢:)

于 2012-05-24T08:22:53.207 回答