VBでファイルの中で時間の順番が並べ替えてほしいです。
(ファイルの中に2000行があります。)
2010 15:03:09
2010 08:03:09
2010 09:07:08
2011 08:07:09
.........
下にコードを書きましたが、実行できなかったです。
お教えてください。
For Each filename In files Dim sr As New System.IO.StreamReader(filename, _ System.Text.Encoding.GetEncoding(932)) 'ストリームの末端まで繰り返す Do While sr.Peek <> -1 ReDim Preserve Line(lineCnt) 'lineにセット Line(lineCnt) = sr.ReadLine() '行の結合 If Not (Line(lineCnt).IndexOf("2010") = 0) Then Line(lineCnt - 1) = Line(lineCnt - 1) & Line(lineCnt) Else lineCnt = lineCnt + 1 End If Loop
Dim temp As String '並べ替えた後の行 Dim val As String '並べ替えた後の時間 For k As Integer = 0 To Line.Length - 1 ReDim Preserve cnt1(k) '年 ReDim Preserve cnt2(k) '時間 Dim i As Integer = 0 Dim j As Integer = 0 While (i < k) j = 0 While (j < k - i) If (cnt1(k) = cnt1(j)) Then If (cnt2(k) > cnt2(j)) Then temp = Line(k) val = cnt2(k) Line(k) = Line(j) cnt2(k) = cnt2(j) Line(j) = temp cnt2(j) = val End If End If j += 1 End While i += 1 End While Next コード
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。