Topic awaiting preservation: how best to parse large amounts of text? (Page 1 of 1) |
|
---|---|
Nervous Wreck (II) Inmate From: |
posted 08-18-2005 00:54
Hello everyone, I was wondering if anyone could give me some tips on how to parse large amounts of text. I play a strategy game through email, the turn report is sent to me, I write out my orders and send it back so on and so on. I normally just do this in notepad but I figured I could write a very basic client in javascript. There are clients already available but I would like to write my own for three reasons, the challenge, I don't really like any of the available clients and I can't install anything at work and I do most of it on my breaks while at work. |
Bipolar (III) Inmate From: Sweden |
posted 08-18-2005 03:11
I also deal with some pretty big amounts of text in some of my apps. code: workText=textToParse myTaxRegions1=[] myTaxRegions2=[] while((/Tax Regions: (\d+) \((\d+)\)/.test(workText)){ myTaxRegions1.push(parseInt(RegExp.$1)) // add the first number to first list myTaxRegions2.push(parseInt(RegExp.$2)) // add second one to second list workText=RegExp.rightContext // cut off the first part of workText since we've already checked there } workText=textToParse
code: workText=textToParse errorTexts=[] errorMsg="" chr=0 while(/Errors during turn/.test(workText.substring(chr))){ start=workText.indexOf("Errors during turn:",chr)+20 // find the start of the message, but skip past what we've already searched and compensate for message length errorMsg=workText.substring(start,workText.indexOf("\n\n",start)) // Extraxt a text string from the message to the empty row (\n\n) errorTexts.push(errorMsg) // Store the messages as whole chunks of text for more parsing chr+=errorMsg.length // move the start position past what was just read }
|
Nervous Wreck (II) Inmate From: |
posted 08-18-2005 18:44
Thank you for the suggestion I think that will work pretty well for what I need. I'll play around and if I have any more specific questions I'll ask. Thanks for you help, I really appreciate it. |