Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

[REBOL] Re: Rebol parsing 101

From: brett:codeconscious at: 2-Oct-2003 16:58

> for example: assume i have string > fcontents > == {09/29/03 ATM/POS ACTIVITY $28.68 (pending) 09/29/03 ATM/POS ACTIVITY
$11.41 09/29/03 ATM/POS ACTIVITY $
> 21.71 ...
Before looking at REBOL you need to identify what the structure of your string is. From my point of view I can see that you have multiple transactions, but I'm not sure how you identify each transaction. For example do they all have "ATM/POS ACTIVITY" as a constant or will that change? Do they all start with a US format date? Will the amounts always begin with a $ sign and will they have commas for thousands? Is the (pending) significant for your application or not? Knowing the answer to these questions and other like them gives you a starting point for deciding how to use Parse. You could use its string breakapart mode, or its block mode. You need to decide whether you want it to handle whitespace or not (/all refinement). Then you can create some rules. For example, *this is not complete*, but gives an idea I think: atm-input: [some trx] atm-trx: [ copy trx-date short-us-date atm-constant copy trx-amt dollar-amount opt [pending?] ] atm-constant: ["ATM/POS" "ACTIVITY"] short-us-date: [2 digit #"/" 2 digit #"/" 2 digit] dollar-amount: [#"$" to #" "] parse input atm-input
> but im not understanding how to isolate the elements > > i suspect i should be able to create something akin to a regular expresion
that i can use as a pattern to apply to the string Some info here http://www.codeconscious.com/rebol/parse-tutorial.html If these ideas don't help, just post another email. Cheers, Brett.