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

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

From: John:Dutcher:highmark at: 7-Mar-2006 9:07

I'm trying to discover the possible cause for an oddity when using the 'offset' parameter as in the 'substr' funtion in the small script below. This sample exercise is a miniaturization of the same phenomenon which I noticed when creating a much larger 'series' item by reading fixed-length records from a file one at a time and valuing some variables with pieces of those records. The notes at the right of the 2nd (uncommented) 'for' loop below indicate that I get the same results and values in the 'print' results when using 'different' starting positions in the series call to 'substr' which uses 'starting position' and 'length' as its parameters. The commented 'for' loop which appears first delivers the correct results.....but I really need to understand why the 2nd loop can use different position 'starting values' in the call ....... and output the same results.....it doesn't seem 'right and proper'. (There are (3) instances of a simulated record in the variable 'sample', each is (38) characters long). Thanks............ John D. ******************************************************************** Rebol[Title: "Sort dsysmst.txt to name sequence"] substr: func [record offset len] [ copy/part at record offset len ] sample: "0015342HORNBECK EDNA A0024667BADGER DONALD R0035457ECONOMOU THOMAS S" ;In this for loop ....all results are as expected ;for i 1 114 38 [ ; ; recnbr: substr sample i + 0 3 ; regnbr: substr sample i + 3 4 ; lname: substr sample i + 7 15 ; fname: substr sample i + 22 15 ; minit: substr sample i + 37 1 ; print [recnbr regnbr lname fname minit] ; ;] ;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] ] halt