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 #28751 is a reply to message #28677] Tue, 08 January 2002 12:58 Go to previous messageGo to previous message
James Kuyper is currently offline  James Kuyper
Messages: 425
Registered: March 2000
Senior Member
William Thompson wrote:

> James Kuyper <kuyper@gscmail.gsfc.nasa.gov> writes:
...

>> 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.
>
>
>
> As far as I can determine, that should work equally as well with arrays as
> with strings. For example,
>
> IDL> test = ['This','is','a','test']
> IDL> btest=byte(test)
> IDL> print,btest
> 84 104 105 115
> 105 115 0 0
> 97 0 0 0
> 116 101 115 116
> IDL> stest = string(btest)
> IDL> help,stest
> STEST STRING = Array[4]
> IDL> print,strlen(stest)
> 4 2 1 4
> IDL> print,stest
> This is a test
>
> You shouldn't have to use a loop.

You're relying there on the fact that btest is a two-dimensional array;
string() converts each row into a seperate string. In the case I'm
worrying about, I would have a single IDL string, containing null
characters at arbitrary positions. Try the following:

btest = [84B,104B,105B,115B,0B,105B,115B,0B,97B,0B,106B,101B,115B,11 6B]
stest = string(btest)

All you get in stest is the 'This'.
[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: Fri Oct 10 06:27:27 PDT 2025

Total time taken to generate the page: 0.56105 seconds