Re: Null terminated strings [message #28673] |
Mon, 07 January 2002 18:26  |
Craig Markwardt
Messages: 1869 Registered: November 1996
|
Senior Member |
|
|
James Kuyper <kuyper@gscmail.gsfc.nasa.gov> writes:
> I'm reading a string-valued file attribute from an HDF file that was
> created using C code. As seems quite reasonable for C programs, the
> attribute was written with a length that includes a terminating null
> character. When I read it in using IDL, that null character got included
> as well. This causes a number of bizarre effects, most notably:
>
> IDL> print,date
> 2001-10-07
> IDL> print,date+'T12:00:00'
> 2001-10-07'T12:00:0
>
> I can handle this particular case by using strmid(date,0,10), but in
> general a file attribute might contain multiple null-delimited strings,
> of unknown length. Is there an efficient way of converting such a string
> into an IDL string array?
What happens when you swizzle it through a STRING-BYTE-STRING
transformation?
I.e.,
date = string(byte(date))
I believe that STRING will ignore any trailing 0-bytes, hence this may
solve your problem exactly, at the expense of some extra CPU.
Good luck,
Craig
--
------------------------------------------------------------ --------------
Craig B. Markwardt, Ph.D. EMAIL: craigmnet@cow.physics.wisc.edu
Astrophysics, IDL, Finance, Derivatives | Remove "net" for better response
------------------------------------------------------------ --------------
|
|
|