Frage

I have a good job and I do not know how to solve this week in my query is this

give me the text below and excel in different fields I have to extract and interpret each text for example "EFFECTIVE" is that it is the effective date and that goes on a field in a excel imagine that A1 is then BETWEEN "SAO" and "LAX" and those 2 cities are going in different fields such as B1 and C1 pro fOR IR14BG is a class that goes in another field as D1 then valid for travel "commencing" is another value in another field and goes "EACH TRIP" in another field could help me?

I know it's not easy to have some basic knowledge just wanted to know how I can identify those points in a string and interpret thank you very much for your help

TRAVEL RESTRICTIONS
    EFFECTIVE: 05JUL 13                                                                           FILED
      BETWEEN SAO AND LAX FOR IR14BG FARES

        VALID FOR TRAVEL COMMENCING ON EACH TRIP ON/AFTER 22JUL 13
        AND ON/BEFORE 30SEP 13.
War es hilfreich?

Lösung

As I see it, you have three options of increasing complexity depending upon the power you need.

Mid and InStr

If the format is static (meaning the spacing stays the same, words like "TRAVEL RESTRICTIONS" and "EFFECTIVE" will always be the same and in the same place), you might be able to split it up using VBA's Mid and InStr functions.

RegExp

If things could be a little off - maybe there are some extra spaces sometimes, or maybe someone could write the date in different ways - you might try using Regular Expressions. You can import the VBScript RegExp object into your VBA project and come up with a pattern to match the data in each line.

Recursive Descent Parser

If neither of those methods is robust enough, you can create your own parser. Be warned, it's not a simple task, but it is the most powerful of the three. The easiest kind of parser to write by hand (which is really the only option you have in VBA) is a Recursive Descent parser. The best resource I found for describing the concepts and process is by Jack W. Crenshaw, called "Let's Build a Compiler!" and you can find it online here.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top