//解析歌词
class Program
{
static void Main(string[] args)
{
//i/o/ inputstream /outstream
//目录是文件夹
//带后缀的是文件
//做一个字符流命名空间IO
// StreamReader sr;//面向字符的输入流
// StreamWriter sr1;//面向字符的输出流
//1创建流对象
StreamReader sr = new StreamReader(@"D:\C#1709\考试\shy\消愁.txt", Encoding.Default);
//读取流
string str;
while ((str = sr.ReadLine())!=null)
{
Tast(str);
// Console.WriteLine(str);//这是一行一行的输出
}
//3关流
sr.Close();
for (int i = 0; i < list.Count; i++)
{
Console.WriteLine(list[i].Time+" "+list[i].Lrc);
}
}
static List<Lrcs> list = new List<Lrcs>();
static void Tast(string str)
{
string[] arr = str.Split(new String[] { "[", ".", ":","]" },StringSplitOptions.RemoveEmptyEntries);
if (arr.Length==4)
{
Lrcs lc = new Lrcs();
lc.Lrc = arr[arr.Length - 1];
lc.Time = long.Parse(arr[0])+1000*60 + long.Parse(arr[1])*1000 + long.Parse(arr[2]);
list.Add(lc);
}
}
}
class Lrcs
{
string _lrc;
long _time;
public string Lrc
{
get
{
return _lrc;
}
set
{
_lrc = value;
}
}
public long Time
{
get
{
return _time;
}
set
{
_time = value;
}
}
}
//读取歌词并把读取到的歌词写到新的txt文件里
//FileStream fs= File.OpenRead(@"D:\C#1709\考试\shy\消愁.txt");//打开
//StreamReader s = new StreamReader(fs,Encoding.Default);//添加目录
// string str= s.ReadLine();//读取
//写出文件
//FileStream fs1= File.OpenWrite(@"D:\C#1709\考试\shy\消愁1.txt");
//StreamWriter s1 = new StreamWriter(fs1);
//string str1;
//while ((str1=s.ReadLine())!=null)
//{
// s1.WriteLine(str1);
//}
////最后的流先关闭,先建的流后关闭
//fs.Close();
//s.Close();
//s1.Close();
//fs1.Close();