Anton .....your response is very insightful ..... and right on the money. 
Thanks so much !!!

John D.



"Anton Rolls" <[EMAIL PROTECTED]> 
Sent by: [EMAIL PROTECTED]
03/08/2006 11:32 PM
Please respond to
[EMAIL PROTECTED]


To
[EMAIL PROTECTED]
cc

Subject
[REBOL] Re: Re-post of 'offset' issue...sorry...the first one came out so 
ugly...........







Rebol uses 1-based indexing (not 0-based, like other languages).
This is probably the source of confusion between the 0 or 1 offset.
Let's look at the behaviour of AT:

                 >> s: "abcd"
                 == "abcd"

                 >> at s 0
                 == "abcd"

                 >> at s 1
                 == "abcd"

                 >> at s 2
                 == "bcd"

And compare with SKIP:

                 >> skip s 0
                 == "abcd"

                 >> skip s 1
                 == "bcd"

So AT is 1-based, but you can use SKIP to get 0-based indexing.

I think the problem with fname (first name) is that it is preceded
by padding spaces, therefore you don't notice when you accidentally
collect one and print it. (It seems this confusion also combined with
the first problem.) To be more sure of what I am printing,
I usually MOLD the values, eg:

                 print [mold recnbr mold regnbr mold lname mold fname mold 
minit]

or you could use REMOLD:

                 print remold [recnbr regnbr lname fname minit]

PROBE is also your debugging friend, because you can put it anywhere
and it doesn't affect the operation of the code.

> substr: func [record offset len] [ 
>    copy/part at record offset len 
> ] 
> 
> sample: "0015342HORNBECK       EDNA           A0024667BADGER DONALD 
> R0035457ECONOMOU       THOMAS         S" 


> ;In the for loop below ......
> 
> ; zero or 1 offset gives same result 
> ; 3 or 4 offset does NOT give same result 
> ; 7 or 8 offset does NOT give same result 
> ; 22 or 23 offset gives same result 
> ; 37 or 38 offset does NOT give same result 
> 
> for i 1 114 38 [ 
> 
>         rec1: substr sample i 38 
>         recnbr: substr rec1 0 3 
>         regnbr: substr rec1 4 4 
>         lname: substr  rec1 8 15 
>         fname: substr  rec1 22 15 
>         minit: substr  rec1 38 1 
> 
>         print [recnbr regnbr lname fname minit] 
> 
> ] 

And now for a more rebolish solution using PARSE:

                 sample: rejoin [
                                 "0015342HORNBECK       EDNA           A"
                                 "0024667BADGER         DONALD         R"
                                 "0035457ECONOMOU       THOMAS         S" 
                 ]

                 digit: charset [#"0" - #"9"]

                 parse/all sample [
                                 any [
                                                 copy recnbr 3 digit
                                                 copy regnbr 4 digit
                                                 copy lname 15 skip
                                                 copy fname 15 skip
                                                 copy minit 1 skip
                                                 (print remold [recnbr 
regnbr lname fname minit])
                                 ]
                 ]

I've assumed the fields are fixed length for each record,
although your posting seemed to put "BADGER DONALD" close
together.

Anton.
-- 
To unsubscribe from the list, just send an email to 
lists at rebol.com with unsubscribe as the subject.





-- 
To unsubscribe from the list, just send an email to 
lists at rebol.com with unsubscribe as the subject.

Reply via email to