标签:des style io color ar sp for 文件 div
类的头文件:
#import <Foundation/Foundation.h>
//FILE_PATH是文件名,
#define FILE_PATH @"/Users/qianfeng/Desktop/FilePath/等妹有钱了.txt"
@interface QFLrcItem : NSObject
{
NSString *_time;
NSString *_lrc;
}
-(void)printTime;
-(void)printLrc;
-(void)setTime:(NSString *)newTime;
-(void)setLrc:(NSString *)newLrc;
-(NSString *)getLrc;
-(NSString *)getTime;
-(id)initWithsetsize;
-(void)test;
-(NSString *)getFile;
-(float)getwithTime:(NSString*)timestr;
@end
类的实现.m文件
#import "QFLrcItem.h"
@implementation QFLrcItem
-(void)printTime{NSLog(@"time:%@",_time);}
-(void)printLrc{NSLog(@"Lrc:%@",_lrc);}
-(id)initWithsetsize{
_lrc = [NSString alloc];
_time = [NSString alloc];
return self;
}
-(void)test{
NSString *str = [NSString stringWithContentsOfFile:FILE_PATH encoding:NSUTF8StringEncoding error:nil];
NSLog(@"歌词是:\n %@",str);
}
-(NSString *)getLrc{return _lrc;}
-(NSString *)getTime{return _time;}
-(NSString *)getFile{
NSString *lrc = [NSString stringWithContentsOfFile:FILE_PATH encoding:NSUTF8StringEncoding error:nil];
return lrc;
}
-(void)setTime:(NSString *)newTime{_time = newTime;}
-(void)setLrc:(NSString *)newLrc{_lrc = newLrc;}
-(float)getwithTime:(NSString*)timestr{
float time;
float mit,sed,hao;
NSString *flag = @"";
//提取时间单位:分钟
flag = [timestr substringWithRange:NSMakeRange(1, 2)];
mit = [flag floatValue];
//提取时间单位:秒
flag = [timestr substringWithRange:NSMakeRange(4, 2)];
sed = [flag floatValue];
//提取时间单位:毫秒
flag = [timestr substringWithRange:NSMakeRange(7, 2)];
hao = [flag floatValue];
//歌词出现的时间点:time
time = (mit*60+sed+hao/100);
NSLog(@"mit = %f",mit);
NSLog(@"sed = %f",sed);
NSLog(@"hao = %f",hao);
NSLog(@"sum = %f",time);
return time;
}
@end
main文件:
#import <Foundation/Foundation.h>
#import "QFLrcItem.h"
int main(int argc, const char * argv[])
{
@autoreleasepool {
NSArray *time_lrc = [NSArray arrayWithObject:@""];
QFLrcItem *item = [[QFLrcItem alloc] init];
NSString *FileStr = [item getFile];
//歌词初步装入数组中:
NSArray *array = [FileStr componentsSeparatedByString:@"\n"];
int count = 0;
for (id obj in array) {
//跳过前四行,留着后面单独处理。
if (count<4) {
}
else{
QFLrcItem *newitem = [[QFLrcItem alloc] init];
NSString *flag = obj;
[newitem setTime:[flag substringToIndex:10]];
[newitem setLrc:[flag substringFromIndex:10]];
time_lrc = [time_lrc arrayByAddingObject:newitem];
}
count++;
}
//单独处理前面四行,(因为前面四行没有时间)
NSString * str1 = @"等妹有了钱\n王振州\n 等我有了钱 \n 王振州 \n";
NSLog(@"%@",str1);
float passtime = 0;
float nowtime = 4.5;
count = 0;
for (id obj in time_lrc) {
if (count==0) {
count++;
continue;
}
nowtime = [obj getwithTime:[obj getTime]];
//暂停时间:
float stoptime = nowtime - passtime;
NSLog(@"stoptime = %f 秒",stoptime);
[obj printTime];
sleep(stoptime);
[obj printLrc];
passtime = nowtime;
}
}
return 0;
}
[ti:等妹有了钱]
[ar:王振州] [al:等我有了钱]
[ar:王振州]
[00:04.50]等妹有了钱
[00:07.17]歌词编写:王振州
[00:11.05]QQ:1259039029
[00:13.17]
[01:32.97]他们都说妹很傻 妹下班就回家
[01:36.19]其实妹是月光族 挣钱不够花
[01:40.26]早出晚归忙工作 不敢去酒吧
[01:43.58]帅哥都会嫌弃妹 不接妹电话
[01:47.26]
[01:47.69]妹年纪越来越大了 还是没人嫁
[01:50.99]二十好几没老公 急坏了爸妈
[01:54.60]日子天天在挣扎 没什么变化
[01:58.35]活着到底为什么 越想越害怕
[02:02.05]
[02:02.51]等妹有了钱 妹想花妹就花
[02:06.13]抽烟抽中华 吃饭妹点大虾
[02:09.88]等妹有了钱 妹什么都不怕
[02:13.56]开车开宝马 购物妹上燕莎
[02:17.02]
[02:17.32]等妹有了钱 妹天天去潇洒
[02:20.92]早上喝早茶 晚上妹泡酒吧
[02:24.61]等妹有了钱 帅哥就一大把
[02:28.34]谁不喜欢妹 妹一定踹了她
[02:31.97]
[03:02.11]他们都说妹很傻 妹下班就回家
[03:04.88]其实妹是月光族 挣钱不够花
[03:09.01]早出晚归忙工作 不敢去酒吧
[03:12.64]帅哥都会嫌弃妹 不接妹电话
[03:15.90]
[03:16.29]妹年纪越来越大了 还是没人嫁
[03:20.01]二十好几没老公 急坏了爸妈
[03:23.91]日子天天在挣扎 没什么变化
[03:27.47]活着到底为什么 越想越害怕
[03:30.84]
[03:31.21]等妹有了钱 妹想花妹就花
[03:34.69]抽烟抽中华 吃饭妹点大虾
[03:38.33]等妹有了钱 妹什么都不怕
[03:42.09]开车开宝马 购物妹上燕莎
[03:45.65]
[03:45.98]等妹有了钱 妹天天去潇洒
[03:49.59]早上喝早茶 晚上妹泡酒吧
[03:53.36]等妹有了钱 帅哥就一大把
[03:56.90]谁不喜欢妹 妹一定踹了她
[04:00.23]歌词编写:王振州QQ:1259039029
[05:30.34]
标签:des style io color ar sp for 文件 div
原文地址:http://blog.csdn.net/u012360598/article/details/41148649