[VS 2003] Best way to get data from text file
Just after a quick piece of advice, I'm trying to write an application that will read stored chess games in .pgn files and eventually replay them move by move on a chess board (thats a way off for now :) )
The advice I'm looking for is the most efficient way to extract the data from the .pgn file (this is all in plain text , see sample below). I need to get the event name, site, date, round ....etc. I initially thought of reading it in one char at a time until I hit a " then store the following characters until I hit the next " etc but this seems a bit long winded is there a better way ?
[Event "Wch U10"]
[Site "Bratislava"]
[Date "1993.??.??"]
[Round "1"]
[White "Martinez, J."]
[Black "Akobian, Varuzhan"]
[Result "0-1"]
[WhiteElo ""]
[BlackElo ""]
[ECO "C02"]
1.e4 e6 2.d4 d5 3.e5 c5 4.c3 Nc6 5.Nf3 Qb6 6.Bd3 Bd7 7.O-O cxd4 8.cxd4 Nxd4
9.Nxd4 Qxd4 10.Nc3 Qxe5 11.Re1 Qb8 12.Nxd5 Bd6 13.h3 Ne7 14.Nxe7 Bxe7 15.Qg4 O-O
16.Bh6 Bf6 17.Qe4 g6 18.Bxf8 Bc6 19.Qb4 Qxf8 20.Qxf8+ Kxf8 21.Be4 Bxb2 22.Rab1 Bd4
23.Bxc6 bxc6 24.Red1 Rd8 25.Kf1 Ke8 26.Ke2 Rd7 27.Kf3 c5 28.g4 Ke7 29.Rb8 e5
30.Rh8 e4+ 31.Kxe4 Bxh8 32.Rxd7+ Kxd7 33.Kd5 Kc7 34.f4 Kb6 35.Kc4 Kc6 36.h4 f5
37.gxf5 gxf5 38.Kd3 Kd5 39.h5 c4+ 0-1
Re: [VS 2003] Best way to get data from text file
Use Streamreader.ReadLine & split(""""c) on the line [Event "Wch U10"] gives you this string array
("[Event ", "Wch U10", "]")... Then get the 2nd element from the array.
VB Code:
Dim line As String
While sr.Peek <> - 1
line = sr.ReadLine()
If line.StartsWith("[") Then
strWhatYouNeed = line.Split(""""c)(1)
End If
End While
Re: [VS 2003] Best way to get data from text file
Thanks for the help it works great :thumb:
I've looked at the dynamic help on split but it really doesn't explain in great detail what's going on, could you tell me what then 'c' does in the split arguments.