View on GitHub

IRAF Community Distribution

IRAF maintained by the community

Home | Installation | Packages | X11IRAF | PyRAF | Forum

chomp

hbar wrote on Dec 04, 2006

Hi,

in a cl script I am trying to read in a string of numbers, e.g. "12,15,19". Is there an easy way to split this string at the delimiter "," into individual components and convert the numbers into integers?

hbar

Mike Fitzpatrick wrote on Dec 04, 2006

If it's a small string as in your example, try

cl> print ("1,2,3") | trans STDIN "," " " | scan (i,j,k)


The TRANSLIT task can do the split, and then you just "scan-from-pipe" into the variables you want. If it's a longer list, instead of a space use "\n" to force a newline, redirect to a file and then read through the file in the usual way.

-Mike

Last post on Dec 04, 2006