我得到了一些网址,指向某些mp3的内容如下:
(1) localhost://blablabla/song1.mp3
(2) localhost://blablabla/songwithmorechars.mp3诸若此类。
如何将URL裁剪到:
(1) song1.mp3
(2) songwithmorechars.mp3需要显示我的AVAudioPlayer正在UILabel中播放的当前歌曲。
谢谢
解决方案:
交易是这样的:
titleLabel.text = [[[self.audioPlayer.url absoluteString] lastPathComponent] stringByReplacingOccurrencesOfString:@".mp3" withString:@""];发布于 2012-04-05 08:26:45
接受带有最后一个/的子字符串(在ObjC中有一个方法!)
NSString *sub = [url lastPathComponent];下面是该方法的信息:
发布于 2012-04-05 08:28:08
只需使用[url lastPathComponent],您不需要首先将其转换为字符串。
发布于 2012-04-05 08:29:56
NSURL *firstURL = [NSURL URLWithString:@"localhost://blablabla/song1.mp3"];
NSString *firstString = [firstURL absoluteString];
NSLog(@"Name:%@",[firstString lastPathComponent]);从医生那里:
https://stackoverflow.com/questions/10025050
复制相似问题