解析文本文件的方法

时间:2012-02-23 17:58:55

标签: c# parsing

我希望为扑克手历史创建一个解析器。我想提取谁是按钮的信息?

我该如何处理?这是一个示例历史文件:

#Game No : 11460450069 
***** Hand History for Game 11460450069 *****
NL Texas Hold'em $1 USD Buy-in Trny:67308896 Level:8  Blinds-Antes(600/1.200 -50) - Wednesday, February 22, 05:48:56 EST 2012
Table Turbo #2533048 (Real Money)
Seat 5 is the button
Total number of players : 2/10 
Seat 5: NAME( 2,898 )
Seat 2: NAME( 17,102 )
Trny:67308896 Level:8 
Blinds-Antes(600/1.200 -50)
NAMEposts ante [50]
NAMEposts ante [50]
** Dealing down cards **
Dealt to NAME[  Th Js ]
NAME is all-In  [2,248]
NAME calls [1,648]
** Dealing Flop ** [ 3h, 2d, 9s ]
** Dealing Turn ** [ Jd ]
** Dealing River ** [ Ad ]
NAME shows [ 5s, Kc ]high card Ace.
NAME shows [ Th, Js ]a pair of Jacks.
NAME wins 5,796 chips from the main pot with a pair of Jacks.
NAME finished in 2 place and won $2.55 USD.

1 个答案:

答案 0 :(得分:2)

文件格式是文件结构的规范。它们通常是二进制的,但在你的情况下,在许多其他情况下,它们都是文本。您需要做的第一件事是决定文档的结构,然后逐行阅读。您还可以使用使此过程更容易的工具,例如基于Parse Grammar规则的工具。我认为,菲利普在答案中提到的ANTLR就是其中一种工具......

相关问题