VB 读文件 ANSI
我在用VB读lrc文件,内容含中文,鉴于vb以unicode形式存字符,显示出的都是乱码,求解决方案。代码附上,不要直接回答什么Strconv() ,无效。LCID都改过了还是没用。
添加timer控件,interval=1000。添加Label,Listbox。
lrc保存为ansi文件就可以了,但是unicode的lrc读不了。
Option Explicit '处理LRC歌词Dim LrcText(0 To 6000) As String 'LRC歌词按s存放在数组中 e.g.第02:05的歌词存放在 LrcText(125)中 //60 * 02 + 05 = 125Public SongName As String, Singer As String, Album As String, Editor As StringPublic LrcOffset As DoubleDim t As IntegerPublic Function LyricsAlalysys(FilePath As String) As Boolean 'LRC歌词分析函数Dim LrcLine() As StringDim Data As String, e As LongDim nFile As Long: nFile = FreeFileOpen FilePath For Input As nFileDo While (Not EOF(nFile)) Line Input #1, Data If Trim(Data) <> Empty Then e = e + 1 ReDim Preserve LrcLine(e) LrcLine(e) = Trim(Data) End IfLoopClose nFileFor e = 1 To UBound(LrcLine) Select Case Mid(UCase$(LrcLine(e)), 1, 4) Case "[TI:": SongName = (Mid(LrcLine(e), 5, Len(LrcLine(e)) - 5)) Case "[AR:": Singer = (Mid(LrcLine(e), 5, Len(LrcLine(e)) - 5)) Case "[AL:": Album = (Mid(LrcLine(e), 5, Len(LrcLine(e)) - 5)) Case "[BY:": Editor = (Mid(LrcLine(e), 5, Len(LrcLine(e)) - 5)) Case "[OFF": LrcOffset = CLng((Mid(LrcLine(e), 9, Len(LrcLine(e)) - 9))) / 1000 Case Else RecordLyric (LrcLine(e)) End SelectNext'[offset:0]——补偿时值。500=0.5秒,正负值分别提前和延长相应的时间End FunctionPrivate Function RecordLyric(Lrc As String)On Error Resume NextDim Lyric As String, Time As StringDim adTime As StringDim min As Long, sec As LongLyric = Mid(Lrc, InStrRev(Lrc, "]") + 1) ' StrConv(..., vbFromUnicode, &H804)Time = Mid(Lrc, 1, InStrRev(Lrc, "]"))Do Until InStr(1, Time, "[") = 0 adTime = Mid(Time, 1, InStr(1, Time, "]")) Time = Replace(Time, adTime, Empty) adTime = Mid(adTime, 2, Len(adTime) - 2) min = CLng(Mid(adTime, 1, InStr(1, adTime, ":") - 1)) sec = CLng(Mid(adTime, InStr(1, adTime, ":") + 1) - LrcOffset) If min >= 0 And min < 100 And _ sec >= 0 And sec < 60 Then LrcText(min * 60 + sec) = IIf(Lyric = Empty, "---Lyric Live!---", Lyric)LoopEnd FunctionPrivate Sub Form_Load()t = 0LyricsAlalysys ("t.lrc") End SubPrivate Sub Timer1_Timer()Label1.Caption = SongName & Singer & Album & Editor & LrcOffsetList1.AddItem LrcText(t)t = t + 1End Sub