16,549
社区成员
发帖
与我相关
我的任务
分享
Imports System.IO
Module Module1
Sub Main()
Dim result = From ln In File.ReadAllLines("data.txt") _
Let datas = ln.Split(","c)
Let key = datas(0).Trim + "," + datas(1).Trim
Group datas By key = key Into g = Group _
Select New With {.key = key, .Sum = g.Sum(Function(x) Integer.Parse(x(2)))}
For Each r In result
Console.WriteLine("{0} = {1}", r.key, r.Sum)
Next
Console.WriteLine("....press any key")
Console.ReadKey()
End Sub
End Module
Imports System.IO
Module Module1
Sub Main()
Dim result = From ln In File.ReadAllLines("data.txt") _
Let datas = ln.Split(","c)
Group datas By key = New With {.A = datas(0), .B = datas(1)} Into g = Group _
Select New With {.key = key, .Sum = g.Sum(Function(x) Integer.Parse(x(2)))}
For Each r In result
Console.WriteLine("{0} = {1}", r.key.A + "," + r.key.B, r.Sum)
Next
Console.WriteLine("....press any key")
Console.ReadKey()
End Sub
End Module
Dim 文件路径 As String = System.Environment.CurrentDirectory + "\新建文本文档.txt"
Dim 内容 As New List(Of String), 暂存 As String = ",,1", 计算 As String()
If New FileInfo(文件路径).Exists Then
Dim 打开 As New FileStream(文件路径, FileMode.Open)
Dim 读取 As New StreamReader(打开)
Dim 判断 = 0
While (读取.EndOfStream <> True)
Dim 取值 = 读取.ReadLine()
判断 += 1
If (暂存.Split(",")(0) <> 取值.Split(",")(0)) Or (暂存.Split(",")(1) <> 取值.Split(",")(1)) Then
If 判断 > 1 Then
内容.Add(暂存)
End If
暂存 = 取值
Else
计算 = 取值.Split(",")
计算(2) = (Int16.Parse(计算(2)) + Int16.Parse(暂存.Split(",")(2))).ToString
内容.Add(String.Join(",", 计算))
判断 = 0
End If
End While
End If