#import <Foundation/Foundation.h>
int main(int argc, const char * argv[]) {
@autoreleasepool {
NSMutableString *mString = [NSMutableString stringWithFormat:@"{\"ret\":0,\"song\":\"九月\",\"singer\":\"许巍\",\"link\":\"http://stream2.qqmusic.qq.com/1295189.wma\",\"lrc\":\"[ti:九月] [ar:许巍] [al:那一年] [00:29.05]我想要离开这浮躁的城市 [00:33.91]我决定去海边看一看落日 [00:38.85]让秋日的海风使我清醒 [00:44.22] [01:04.08]我想到昨天风吹动的夜晚 [01:09.15]坐在我身边我所有的朋友 [01:14.13]岁月让我们已变得沉默 [01:19.15]没有人再会谈论明天 [01:23.67] [01:24.23]有一些希望和理想 [01:28.84]总在心里是最美的旋律 [01:33.88]可如今这真实的生活 [01:38.82]却演奏着那纷乱的节奏 [01:45.13] [02:04.23]就好像战争这对手是自己 [02:09.30]至少我现在已决不会逃避 [02:14.01]那理想的彼岸也许不存在 [02:19.07]我依然会走在那旅途上 [02:23.59] [02:24.31]有一些希望和理想 [02:28.98]总在心里是最美的旋律 [02:34.04]可如今这真实的生活 [02:39.07]却演奏着那纷乱的节奏 [02:44.08]有一些希望和理想 [02:49.11]总在心里是最美的旋律 [02:54.05]到如今它再一次响起 [02:59.09]又飘荡着在我心里 [03:05.06] 我怕冷oicq:18268082 \"}"];
NSArray *array = [mString componentsSeparatedByString:@"]"];//在"]"位置把歌词截断,变成数组.
NSMutableArray *mArray = [NSMutableArray arrayWithArray:array];//变成可变数组
NSMutableArray *mArray1 = [NSMutableArray array];//定义数组 [NSMutableArray new]
for (int i = 0; i < mArray.count; i++)
{
NSString *string = mArray[i];//接受字符串
if ([string containsString:@"[ti:"])//获取位置
{
NSRange range = [string rangeOfString:@"[ti:"];
string = [string substringFromIndex:range.location + 1];
[mArray1 addObject:string]; //把处理好的字符串加入新的数组里面
}
else if ([string containsString:@"[ar:"])
{
NSRange range = [string rangeOfString:@"[ar:"]; //rangeOfString:???
string =[string substringFromIndex:range.location + 1];
[mArray1 addObject:string];
}
else if ([string containsString:@"[al:"])
{
NSRange range = [string rangeOfString:@"[al:"];
string = [string substringFromIndex:range.location + 1];
[mArray1 addObject:string];
}
else if ([string containsString:@"\"}"])
{
NSRange range = [string rangeOfString:@"\"}"];
string = [string substringFromIndex:range.location];
[mArray1 addObject:string];
}
else
{
NSRange range = [string rangeOfString:@"["];
{
}
string = [string substringToIndex:range.location];
[mArray1 addObject:string];
}
}
//快速枚举
for (NSString *ele in mArray1) {
NSLog(@"%@",ele);
}
}
return 0;
}
按规律输出歌词
最新推荐文章于 2024-08-30 10:45:15 发布