在我的M.U.G.E.N锦标赛程序中,我想处理日志文件中的匹配结果,这个日志文件是由游戏创建的。日志如下所示:
[Match 1]
totalmatches = 1
team1.1 =
team2.1 =
stage = stages/kowloon.def
[Match 1 Round 1]
winningteam = 1
timeleft = -1.00
p1.name = Knuckles the Echidna
p1.life = 269
p1.power = 0
p2.name = Shadow the Hedgehog
p2.life = 0
p2.power = 2684
[Match 1 Round 2]
winningteam = 2
timeleft = -1.00
p1.name = Knuckles the Echidna
p1.life = 0
p1.power = 1510
p2.name = Shadow the Hedgehog
p2.life = 586
p2.power = 2967
[Match 1 Round 3]
winningteam = 2
timeleft = -1.00
p1.name = Knuckles the Echidna
p1.life = 0
p1.power = 3000
p2.name = Shadow the Hedgehog
p2.life = 789
p2.power = 777我想要的是处理最后一个winningteam属性来确定匹配的结果。要做到这一点,最有效的方法是什么?(也许是LINQ)
发布于 2017-12-03 19:53:21
您可以使用File.ReadLines作为IEnumerable<string>返回行的枚举。
// string path contains file path and file name.
string line = File.ReadLines(path)
.LastOrDefault(ln => ln.StartsWith("winningteam ="));现在在=中拆分字符串,修剪第二部分,然后将团队号作为字符串
if (line != null) {
string team = line.Split('=')[1].Trim();
// With "winningteam = 2", [0] = "winningteam ", [1] = " 2"
// Optionally convert it to a number
int teamNo = Int32.Parse(team);
...
}https://stackoverflow.com/questions/47622492
复制相似问题