处理歌词数组的方案--
-componentsSeparatedByString:此方法,
通过”\n”字符进行对字符串分割,并且将歌词数组分成两个数组分别如下格式:{
"[00:01.00”,
作词 : Wiz Khalifa
}
例子:
NSMutableArray * lyricsArray = [[NSMutableArray alloc]init];
NSString*ly = @"[00:01.00] 作词 : Wiz Khalifa\n[00:10.440]It's been a long day without you my friend\n";
第一种方法
NSArray *arr = [ly componentsSeparatedByString:@"\n"];
for (int i = 0; i < arr.count; i++) {
NSLog(@"%@",arr[i]);
}
第二种方法
//hasPrefix:(NSString *) astring; 检查字符串是否以astring开头;
//hasSuffix:(NSString *) astring; 检查字符串是否以astring结尾;
while ([ly hasSuffix:@"\n"]) {
NSRange range;
range = [ly rangeOfString:@"\n"];
if (range.location != NSNotFound) {
NSString *string1 = [ly substringToIndex:range.location + range.length];
NSLog(@"%@",string1);
ly = [ly substringFromIndex:range.location + range.length];
[lyricsArray addObject:string1 ];
}