comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Null terminated strings
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
Re: Null terminated strings [message #28752 is a reply to message #28677] Tue, 08 January 2002 11:51 Go to previous messageGo to previous message
Craig Markwardt is currently offline  Craig Markwardt
Messages: 1869
Registered: November 1996
Senior Member
James Kuyper <kuyper@gscmail.gsfc.nasa.gov> writes:
> Craig Markwardt wrote:
...
>> 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.
>
> Thanks - that worked. It only solves the single-string case, but that's
> the case I am currently facing. It saves me the trouble of figuring out
> how long the string is, and it does the right thing, whether or not the
> string is null-terminated.
>
> I'm still wonder how to best convert a null-delimited list of strings
> into an IDL string array (it's just curiousity, I don't have any
> immediate need for that ability). My best solution so far is to convert
> it to a byte array, find the null delimiting characters with where(),
> and then write a loop to convert each subarray into a seperate IDL
> string. This should work, but I'm always suspicious of the efficiency of
> any solution for an IDL problem that involves an explicit loop.

The problem is that IDL has no way to represent the 0th ASCII
character in a string. At least no way that I can find, other than
bringing the data in from outside, as you have done with HDF.

My best solution is to do as you have, which is to convert to BYTEs,
then locate the 0's. But at this stage you can quickly replace the
0's with some other control character, say ASCII 1. [ This assumes
that 1 = CTRL-A never appears in your strings. ] Then you can convert
back to string and use STRSPLIT or STR_SEP to split it up.

However, you should be aware that STR_SEP uses FOR loops, and I have
never really noticed an impact when I've used it. Unless your code is
*actually* a dog with FOR loops, versus *hypothetically* a dog, then
there is no reason to optimize it. :-)

Craig

--
------------------------------------------------------------ --------------
Craig B. Markwardt, Ph.D. EMAIL: craigmnet@cow.physics.wisc.edu
Astrophysics, IDL, Finance, Derivatives | Remove "net" for better response
------------------------------------------------------------ --------------
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Re: WIDGET REALIZATION BUG in 5.5 ?
Next Topic: Re: Spherical Contour Plotting

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Wed Oct 08 18:58:48 PDT 2025

Total time taken to generate the page: 0.00453 seconds