PlanetSquires Forums

Please login or register.

Login with username, password and session length
Advanced search  

Author Topic: Extracting info from a large string and fields  (Read 105 times)

Petrus Vorster

  • Senior Member
  • ***
  • Posts: 437
Extracting info from a large string and fields
« on: September 18, 2019, 05:58:15 PM »

Hi All

I am trying to update one of my Powerbasic projects.

It retrieves information from a website using a TCP open command.
What i get back is a pile of text with several kinds of delimiters.
I assume its Code block start and end lines what is used by the site to display data on the whereabouts of an item in a list format.

{ is code block start and  } is code block end.
Information in between is in parentheses "Tracking Status":"-1" and so forth.

All they do is give you a history breakdown, top to bottom on the site so you can read the progress till the end / delivered / returned etc.

I would like to extract information from that big block of information, only to retrieve whether it has been returned or delivered locally.

I found the code for "Delivered" and "Returned" and can extract that with REGEXPR successfully.
What i want to do next is try and retrieve the dates and names in that code block in which i found that Delivered marker.
In the entire big chunk of info there are many dates (Transport dates, Posting dates etc).

So what i know, is if i find the Returned marker or the Delivered marker, there will be somewhere to the left a "{" marker and somewhere to the right a "}" marker. (variable lengths strings)
How could one search only for certain keywords between only those specific two markers?

In other words, how do I search for the first instance of "{" to my current position in a text block and the first instance to my right of "}"?
The in-between part i should be able to extract with REGEXP.

Hope this is understandable.

regards, Peter
Logged

raymw

  • Senior Member
  • ***
  • Posts: 284
Re: Extracting info from a large string and fields
« Reply #1 on: September 18, 2019, 08:40:34 PM »

I know nothing, other than having heard the term, years ago, about regex, but if you could do what you want in pb, then you could most likely do it in fb. Without knowing the full details, I would read in a chunk of the data, look for the keywords you know, then use mid/left/right whatever to get the {}. Then pull  out what you need. Probably quickest to search for the rarest occurrences first. If the block terminator } is always followed by { to start next block, then you only need to search for { if going from left to right. I think {+ in regex will get the previous instance of {, from my quick scan of the wikki.
Logged

Petrus Vorster

  • Senior Member
  • ***
  • Posts: 437
Re: Extracting info from a large string and fields
« Reply #2 on: September 19, 2019, 02:58:02 AM »

Thanks

I think i will first break it down starting from the beginning of the big block of text, finding all the smaller code blocks starting and ending with { }.
Then remove those i dont need.
Once i have a string containing only the one code block needed, it should be easy.
Will let you know what happened..

-Peter
Logged

raymw

  • Senior Member
  • ***
  • Posts: 284
Re: Extracting info from a large string and fields
« Reply #3 on: September 19, 2019, 07:10:41 AM »

Hi Peter,
It's maybe just semantics, but if you're reading a chunk of data into memory, instead of removing blocks you don't need, save the blocks you do need to another string/file. Inevitably you will need to find more information about them. What will happen, you'll got to your boss with the results of the first inquiry, he/she/it will be impressed and then ask something like 'how many of these deliveries were on a Friday?' Don't immediately go back with the answer to this second question, 'cos then you'll get asked a third, fourth and so on.
Logged