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

[REBOL] Seeming 'oddity' using the 'offset' parm with 'copy/part' ..........

From: John::Dutcher::highmark::com at: 7-Mar-2006 8:46

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 understnd 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' below, each is (38) characters long). Thanks............ John D. ******************************************************************** Rebol[Title: "Sample copy/part script"] substr: func [record offset len] [ copy/part at record offset len ] sample: "0015342HORNBECK EDNA A0024667BADGER DONALD R0035457ECONOMOU THOMAS S" ;for i 1 114 38 [ ; ; recnbr: substr sample i + 0 3 ; regnbr: substr sample i + 3 4 ; lname: substr sample i + 7 15 ;This version using the 'i' varibale plus what I consider the 'correct' adjustment ; fname: substr sample i + 22 15 ; produces the expected result presuming 'series' start at offset '1' ; minit: substr sample i + 37 1 ; print [recnbr regnbr lname fname minit] ; ;] ; should be able to use 'fixed' offset values and get correct result also ; doesn't seem as though more than one 'starting position' could possibly ; deliver the same results ........and yet.....it seems to. for i 1 114 38 [ rec1: substr sample i 38 recnbr: substr rec1 0 3 ; zero or 1 offset gives same result regnbr: substr rec1 4 4 ; 3 or 4 offset does NOT give same result lname: substr rec1 8 15 ; 7 or 8 offset does NOT give same result fname: substr rec1 22 15 ; 22 or 23 offset gives same result minit: substr rec1 38 1 ; 37 or 38 offset does NOT give same result print [recnbr regnbr lname fname minit] ] halt