lyric歌词文件整理排序
获取歌词并排序:
ArrayList LrcArr = new ArrayList();
private void LoadLyric(string LrcStr)
{
string[] listArr = LrcStr.Split('\n');
Regex reg = new Regex(@"[[0-5][0-9]:[0-5][0-9].[0-9][0-9]]");
for (int i = 0; i < listArr.Length; i++)
{
string lrc = listArr[i];
int len = reg.Match(lrc).Length + 1;
MatchCollection mc = null;
mc = reg.Matches(lrc);
string lyric = lrc.Substring(len * mc.Count);
for (int j = 0; j < mc.Count; j++)
{
ObjLrc obj = new ObjLrc();
string ctime = mc[j].Value.Replace("[","").Replace("]","");
String[] s = ctime.Split(':');
double ntime = int.Parse(s[0]) * 60 + double.Parse(s[1]);
obj.timer = ntime;
obj.lyric = lyric;
LrcArr.Add(obj);
}
}
IComparer myComper = new Comparer();
LrcArr.Sort(myComper);
for (int i = 0; i < LrcArr.Count; i++)
{
ObjLrc obj = new ObjLrc();
obj = (ObjLrc)LrcArr[i];
textBox3.Text+=obj.timer.ToString() + obj.lyric+"\r\n";
}
}
排序方法:
public class Comparer:IComparer
{
int IComparer.Compare(object A, object B)
{
ObjLrc paraA = (ObjLrc)A;
ObjLrc paraB = (ObjLrc)B;
if (paraA.timer > paraB.timer)
{
return 1;
}
if (paraA.timer < paraB.timer)
{
return -1;
}
return 0;
}
}
歌词结构:
struct ObjLrc
{
public double timer;
public string lyric;
}
浙公网安备 33010602011771号