CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Jan 2009

    Newbie question - text parser

    Im not really too sure where to start. I've got a really basic overview of programming but nothing enough of note. I don't really know what type of language is best to code in for my particualar idea, but im quite happy learning.

    Generally there is a text file that is updated every few seconds by a game. it records a log, of each individual activity that happens, each line preceded by a timestamp. In each line of the log there is a name and 2 different numbers i want to parse that i then want to combine to give me a percentage for that name - but ignoring the other text that is recorded around it. then i can then have a small graphical interface that presents the name and the percentage its found.

    I'll run through an example, it might help explain what i'd want to do:

    each line in the log looks like this or similar variations of:

    [System Message] 23:28:29 IG88 shouts: Still here? I can spare a few battle droids for these intruders!
    [Combat] 23:28:29 Battle Droid attacks Iasha with droid explosion and hits for 531 points (326 kinetic and 205 heat). Armor absorbed 866 points out of 1397.

    1) ignore any [System Message] lines
    2) choose [Combat] line
    3) check for both attacks Iasha andand hits for in line
    4) skip if either isn't there, reload the text file log and procede to next line and repeat from step 1
    5) input/display the name that will appear between the time (that is always in the format ##:##:##) and attacks Iasha on a small interface labeled as Name
    6) input/savethe single word followingpoints (### - will be either kinetic or energy - this informs if the following numbers go into colum 1 or 2 on the main display.
    7) input/display the number that is between Armor absorbed and points out of as "Absorbed kinetic" (or energy if step 6 indicates that instead)
    8) input/display the number that is between points out of and . as "Total kinetic" (or energy if step 6 indicates that instead)
    9) display a Percentage of the displayed "Absorbed" value and "Total" for kinetic.
    10) keep these values (ie for kinetic) for a perhaps 10 seconds before wiping them but still process for the other (kinetic or energy) from step 6
    11) reload the text file log again and repeat from step 1 but also now check that the name is also now the same as well.
    12) then if no energy (or kinetic alternativley) is found then wipe all saved data, re-load the text file log again proceed from step 1.

    here is a link of kinda what i'd have in mind to display the info - or at least as a guide to accompany the steps.

    If anyone is at the least able to point out a more appropirate coding language to start with for this, and perhaps a guide or pointer on how start/research text parsing, saving the parsed text & numbers, do simple math with them and have them display in some form - id be really greatefull.

    I could just guess, read up say java or C++ and find its either not possible to do or would be far easier with a different type of coding language. or even just take ages trying to decipher where to start to find the basic functions i need to do.

    Many thanks


  2. #2
    Join Date
    Jan 2006
    Fox Lake, IL

    Re: Newbie question - text parser

    Use VB.Net or C#, and you have the FolderWatcher class that fires events automatically when a folder changes.

    That could also fire to update your calculations and gui

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  3. #3
    Join Date
    Mar 2004

    Re: Newbie question - text parser

    the best language for parsing strings is Perl. Perl uses regular expressions. Using regular expressions you'll simply say how a string looks like and perl will pretty much find it for you.

    $text = "hello I'm 42 and have 43 magic points"
    if($text =~ m/hello I'm (\d+)/){
       $age = $1;
    if($text =~ m/(\d+) magic points/){
      $mp = $1;
    print "age: $age\n", "magic points: $mp";
    Results in terminal
    age: 42
    magic points: 43

    "\d+" means a number with any number of digits. the brackets () means; what ever has been found in between is stored in $1, the next bracket will be stored in $2 and etc...

    And for displaying stuff you can use GTK+, with libglade to create user interfaces fast . Or really simply you can use the console or create a webpage where you can simply refresh the browser to reload the html file.

    Google perl tutorial

  4. #4
    PeejAvery's Avatar
    PeejAvery is offline Super Moderator Power Poster
    Join Date
    May 2002

    Re: Newbie question - text parser

    Most common languages today have regular expressions. I would use PHP over Perl, but I don't think a scripting language would be best for this situation.

    I would go with dglienna's suggestion. Monitoring the log folder would make it so that the scripts do not have to be user initiated. Plus, both VB.NET and C# have regular expressions.
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Windows Mobile Development Center

Click Here to Expand Forum to Full Width

On-Demand Webinars (sponsored)

We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.