[Date Prev][Date Next][Thread Prev][Thread Next]
[Author Index] [Date Index] [Thread Index]
[SQR-USERS Info] [SQRUG Home Page]

Re: split the ting into an array



my 2 cents
--------------------------
BEGIN-REPORT
  DO PROCESS-MAIN
END-REPORT

BEGIN-PROCEDURE PROCESS-MAIN

let $testit='asd$ddd$xxx$yyyy'   ! in this sample delim is $ not chr(10)
display $testit

CREATE-ARRAY NAME=vart  size=400  ! the array will hold the vars
  FIELD=var:CHAR=''
let #varcnt = 0                   ! counter for vars

let $testit='asd$ddd$xxx$yyyy'   ! a test string
LET #lenbig = length($testit)
LET #posbig = 0
let $wvar = ''

WHILE #posbig < #lenbig
   let #posbig = #posbig + 1
   if substr($testit,#posbig,1) = '$'   ! found end of var
      let #varcnt = #varcnt + 1         ! store in array
      let vart.var(#varcnt) = $wvar
      let $wvar = ''                    ! start new
   else
      let $wvar = $wvar || substr($testit,#posbig,1)    ! else add to array
   end-if
end-while

let #varcnt = #varcnt + 1          ! assume last item has no
let vart.var(#varcnt) = $wvar      ! trailing delimiter

WHILE #xxx < #varcnt           ! did it work
   let #xxx = #xxx + 1
   let $disp = vart.var(#xxx)
   display $disp
end-while

END-PROCEDURE



>Hello All:
>
>I have a PL/SQL package that I call from within SQR that returns a number of
>variables concatenated together by carriage returns (chr(10)      i.e... $items
>= VAR1[]VAR2[]VAR3[].....VAR100.. (where [] is a carriage return).
>
>I have to take the string $items, unstring it by [] and print the results on
>their own lines.  Easy enough.  The problem is that I do not know the number of
>variables that the string contains.  It could be from 1 to 100 and I do not
want
>to hard code one hundred variables in an unstring command.  ie.... unstring by
>'[]' into $var1 $var2.........$var100.
>
>Does anyone have any ideas ?
>
>
>Thanks,
>
>Phil Roell
>National Instruments
>Manufacturing IS
>
>