none
C#播放器 读取本地歌词时出现乱码问题 RRS feed

  • 问题

  • using TXTClass;
    using System.Text.RegularExpressions;
    using System.Collections;
    using System.Windows.Forms;
    using System.Collections.Generic;
    using System;
    using System.Data;
    using System.Text;
    using System.IO;
    
    namespace form1
    {
        class ShowLrc
        {
            txtclass txt = new txtclass();
            string excTime = @"(?<=\[).*?(?=\])";//匹配时间的正则
            string excText = @"(?<=\])(?!\[).*";//匹配歌词的正则
            string[] lrcTime = new string[200];//保存歌曲时间
            string[] lrcText = new string[200];//保存歌词文字
            int t1=0;
            int t2 = 0;
            string zj;//中间变量
    
            /// <summary>
            /// 解析lrc文件
            /// </summary>
            /// <param name="FileName">文件路径</param>
            public void getLrc(string FileName)
            {
                t1 = 0;
                t2 = 0;
                lrcTime = new string[200];
                lrcText = new string[200];
                Encoding.GetEncoding("gb2312");
                string[] strs= System.IO.File.ReadAllLines(FileName,Encoding.Default);
                int hasline = strs.Length;
                MatchCollection match1;
                MatchCollection match2;
                for (int i = 0; i <= hasline; i++)
                {
                    match1 = Regex.Matches(txt.txtRead(FileName,i),excTime);
                    match2 = Regex.Matches(txt.txtRead(FileName,i),excText);
                    foreach (var v in match1)
                    {
                        StringBuilder sb = new StringBuilder(v.ToString());
                        sb.Replace(".",":");
                        zj = sb.ToString();
                        try
                        {
                            zj = zj.Substring(0, 5) + ":00";
                            //try
                            //{
                                System.DateTime.Parse(zj);
                                lrcTime[t1] = zj;
                                foreach (var t in match2)
                                {
                                    lrcText[t2] = t.ToString();
                                 }
                                t1++;
                                t2++;
                            //}
                            //catch (System.Exception)
                            //{
    
    
                            //}
                        }
                        catch (Exception)
                        {
                            
                            //
                        }
                            
                    }
                    
                }
            }
    
            //返回数组
            public string[] returnTime()
            {
                return this.lrcTime;
            }
    
            public string[] returnText()
            {
                return this.lrcText;
            }
        }
    }
    
    播放器读取 本地 歌词出现乱码......
    • 已移动 Fred Bao 2015年4月30日 7:40 C# Related
    2015年4月29日 13:04

答案

全部回复

  • 这个问题是C#开发相关的,我帮你移到C#论坛,那里有C#专家帮你看这个issue,当前你发的论坛是用于讨论ADO.NET与LINQ相关的问题。


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    2015年4月30日 7:39
  • 试过了,没有用
    2015年5月3日 9:58