MF 的个人资料CMF.net照片日志列表更多 ![]() | 帮助 |
|
11月23日 讀取檔案中的數字並統計出現次數- 使用 VB.NET Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim DataStr As String Dim NumStr As String Dim re As System.IO.StreamReader = System.IO.File.OpenText("C:\DBS.txt") Dim NumDict As New Dictionary(Of String, Integer)() Dim input As String = Nothing Do input = re.ReadLine() If Not input Is Nothing Then Dim s As String() = input.Split(","c) If s.Length = 2 Then DataStr = s(0) NumStr = s(1) If Not NumDict.ContainsKey(NumStr) Then NumDict.Add(NumStr, 1) Else NumDict(NumStr) += 1 End If End If End If Loop Until input Is Nothing re.Close() Dim msg As String = "統計:" + Environment.NewLine Dim count As Integer For Each ks As String In NumDict.Keys count = NumDict(ks) msg = msg + ks + "出現" + count.ToString() + Environment.NewLine Next MessageBox.Show(msg) End Sub =============== |
|
|