AFterlife Posted September 14, 2006 Posted September 14, 2006 (edited) [PLAIN][RESOLVED]Parsing a file with RegEx[/PLAIN] Hi. I normally use substring and other methods to parse files.But I wanted to try something new.I am parsing the file as its streaming from an FTP server on the Web with ASP.Maybe I am in the wrong section.Plus my first time using REgEx..lol.I downloaded that espresso regex tutorial last night. I am having a problem retriveing all of the player names and I don't know why. Here is a small example output of the file.Oh and my first time trying 2005.I have used 2002 or 2003 in the past. 1158089131 [Tue Sep 12 14:25:31 2006] [Tue Sep 12 14:25:31 2006] ------------------------------------------ [Tue Sep 12 14:25:31 2006] Server started. [Tue Sep 12 18:26:22 2006] Client connected: StoNer [Tue Sep 12 18:26:51 2006] Client connected: ||3RB||Multigun [Tue Sep 12 18:34:52 2006] Client connected: B&F_PROSMOKER [Tue Sep 12 18:36:20 2006] Client connected: ChibiPyro [Tue Sep 12 18:38:40 2006] Client connected: [TF]Sabrina [Tue Sep 12 18:40:14 2006] Client connected: RED_jºnbºy [Tue Sep 12 18:40:42 2006] Client connected: Kalekemo [Tue Sep 12 18:40:46 2006] Client disconnected: RED_jºnbºy [Tue Sep 12 18:41:39 2006] Client connected: ConChip [Tue Sep 12 18:43:35 2006] Client connected: Player [Tue Sep 12 18:45:15 2006] Client disconnected: ConChip [Tue Sep 12 18:45:34 2006] Client disconnected: B&F_PROSMOKER [Tue Sep 12 18:46:31 2006] Client disconnected: Player [Tue Sep 12 18:46:41 2006] Client connected: Player [Tue Sep 12 18:46:47 2006] Client disconnected: Player [Tue Sep 12 18:48:09 2006] [Tue Sep 12 18:48:09 2006] *** Results for Map: Worlds\ReleaseMultiplayer\DOOME4M9v2 [Tue Sep 12 18:48:09 2006] [Tue Sep 12 18:48:09 2006] Team: Team 1 [Tue Sep 12 18:48:09 2006] Score: 7 [Tue Sep 12 18:48:09 2006] [Tue Sep 12 18:48:09 2006] Player: StoNer (uid: ce35bbd1d0cfeb354ad6c51a45e86a80) [Tue Sep 12 18:48:09 2006] Score: 771 [Tue Sep 12 18:48:09 2006] Kills: 30 [Tue Sep 12 18:48:09 2006] Deaths: 16 [Tue Sep 12 18:48:09 2006] Team Kills: 0 [Tue Sep 12 18:48:09 2006] Suicides: 1 [Tue Sep 12 18:48:09 2006] Objective: 645 [Tue Sep 12 18:48:09 2006] [Tue Sep 12 18:48:09 2006] Player: [TF]Sabrina (uid: 3a9f1c3bcabec404751b8ce6db9b3f78) [Tue Sep 12 18:48:09 2006] Score: 20 [Tue Sep 12 18:48:09 2006] Kills: 3 [Tue Sep 12 18:48:09 2006] Deaths: 6 [Tue Sep 12 18:48:09 2006] Team Kills: 0 [Tue Sep 12 18:48:09 2006] Suicides: 0 [Tue Sep 12 18:48:09 2006] Objective: 10 [Tue Sep 12 18:48:09 2006] [Tue Sep 12 18:48:09 2006] Team: Team 2 [Tue Sep 12 18:48:09 2006] Score: 2 [Tue Sep 12 18:48:09 2006] [Tue Sep 12 18:48:09 2006] Player: ||3RB||Multigun (uid: b9e14e8150b253cd0e8a6188dec759c1) [Tue Sep 12 18:48:09 2006] Score: 318 [Tue Sep 12 18:48:09 2006] Kills: 13 [Tue Sep 12 18:48:09 2006] Deaths: 27 [Tue Sep 12 18:48:09 2006] Team Kills: 0 [Tue Sep 12 18:48:09 2006] Suicides: 2 [Tue Sep 12 18:48:09 2006] Objective: 290 [Tue Sep 12 18:48:09 2006] [Tue Sep 12 18:48:09 2006] Player: ChibiPyro (uid: 9c2e0c51e128fd45f3bab7a8cc9a2282) [Tue Sep 12 18:48:09 2006] Score: 188 [Tue Sep 12 18:48:09 2006] Kills: 13 [Tue Sep 12 18:48:09 2006] Deaths: 12 [Tue Sep 12 18:48:09 2006] Team Kills: 0 [Tue Sep 12 18:48:09 2006] Suicides: 0 [Tue Sep 12 18:48:09 2006] Objective: 135 Basically I am creating a Player stats system.I Have 2 classes.CPlayer the defines all the attributes of a player and a CPlayerList(The one I am having problems with Class).This Class creates instances of Cplayer and parses the file then adds them to a collection that can be retrieved by index number.It seems like its starts about 3 players down from top and 3 players up from bottom.My hope was to parse this file everynight once a day and then save it to a file on a different webserver.Parsed comma delimited so it's easy to use.I thought maybe it was having problems reading and parsing the data at the same time.But there is no application.doevents() in ASP.Maybe Threading? I'll show you just the part that seems to be a miss... Try Dim Player As CPlayer Do While reader.Read Dim myPlayer As String If GetPlayerNames(myPlayer) <> Nothing Then Player = New CPlayer Player.Name = GetPlayerNames(myPlayer) lbox.Items.Add(Player.Name) End If Loop reader.Close() Catch ex As Exception End Try 'The Function here Public Function GetPlayerNames(ByVal myPlayer As String) As String Dim reg As Regex = New Regex("\:+\s[a-zA-Z0-9<>?,.{}+_&=!@#$%-|`*^:/;()~]+\s*\(u*") Dim m As Match = reg.Match(myPlayer) myPlayer = m.Value.TrimStart(": ") Dim temp As String = myPlayer.Replace("(u", " ") Return temp End Function EDIT:I figured it out I had to do this Do While reader.Read Dim myPlayer As String Dim TempPlayers As String myPlayer = reader.ReadLine TempPlayers = GetPlayerNames(myPlayer) If TempPlayers <> Nothing Then Player = New CPlayer Player.Name = GetPlayerNames(myPlayer) cList.Items.Add(Player.Name) End If Edited September 14, 2006 by AFterlife Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.