Parsing

Started by
1 comment, last by Zorbfish 21 years, 1 month ago
I can''t seem to figure out a good way to tackle the problem Im parsing a text chunk in a tablelike format Unit Total Attacking I have no problem parsing the lines I just check for spaces in between each column in the string. But then this problem occured: Red Wizard 50 Trolls Now checking for spaces doesn''t work because it stops at the space between red and wizard. I have a similar problem if the unit being attack had a space. I''m coding this in vbscript for my website str_start '' Starting Marker str_stop '' Ending Marker str_start = 1 '' Start at beginning of string '' Place End Marker where first " " occurs in string line str_stop = InStr(str_start, line, " ", 1) '' Grab the sub string; length is stop - start unit = Mid(line, str_start, str_stop - str_start) I don''t need the solution to be in vbscript as this is a very generic problem. Any insight into a solution would be appreciated. Zorb
Advertisement
Well, consider the information you have available; you can''t count on spaces as field delimiters, but the middle field is always a numeral. So read each word, find the one that''s a number, and then concatenate all the previous fields as the "Unit" and all the subsequent fields as the "Attacking".

But... but that''s what HITLER would say!!
Generally, you would use something like:

  • comma-separated values (but then you''d have a problem if the name contains a comma)
  • a fixed with for each column (which may be limiting and wasteful)
  • use quotes. In its simplest form: If the word you''re loading starts with a quotation mark, keep loading and adding to it until you get a word that ends with one.


Kippesoep

This topic is closed to new replies.

Advertisement