[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Odd string/index problem



wmc@bas.ac.uk wrote:
> 
> Can someone explain this to me:
> 
> wmc> a='stoat'
> wmc> print,a([0]),'>'
> stoat
> >
> wmc> print,a(0),'>'
> stoat>
> 
> This irritation surfaced when I tried to do
> i=where(strings eq somestring)
> print,strings(i)
> 
> which needs to be
> i=i[0]
> print,strings(i)
> 
> but why?
> 
> -W.
> 
> --
> William M Connolley | wmc@bas.ac.uk | http://www.nerc-bas.ac.uk/icd/wmc/
> Climate Modeller, British Antarctic Survey | Disclaimer: I speak for myself

This is because your i is an array, while i[0] is a scalar.
therefore strings(i) is a string array, while strings(i[0]) is a scalar.

IDL> strings=strarr(10)
IDL> help,strings(1)
<Expression>    STRING    = ''
IDL> help,strings([1])
<Expression>    STRING    = Array[1]           

after printing an array, IDL always starts a new line
cheers,
:-) marc