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

Home » Public Forums » archive » function to convert string to array???
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: function to convert string to array??? [message #3904 is a reply to message #3843] Thu, 30 March 1995 00:00 Go to previous messageGo to previous message
zawodny is currently offline  zawodny
Messages: 121
Registered: August 1992
Senior Member
In article <1995Mar29.192708.17563@alw.nih.gov> cox <cox@colt.cpi.com> writes:

> Here is my routine which converts a string of space or comma-delimited
> items into a string array. It doesn't assume what the output should
> be, so it doesn't convert to FLOAT of INTEGER. It avoids the use of
> loops and makes as much use as possible of built-in IDL functions.
> It should work with ASCII and non-ASCII character sets.
>
> ;+
> ; NAME:
> ; parse_string
> ;
> ; PURPOSE:
> ; This procedure was written to parse a string for substrings
> ; separated by either spaces or commas.

Some stuff deleted

> SpacePos = where(ByteStrng eq Separators(1), count)
> count = count + 1
>
> SubString = strarr(count)
> SpacePos = [-1,SpacePos,strlen(strng_)+1]
> for i = 0, count - 1 do begin
> SubString(i) = strmid(strng_, SpacePos(i)+1, SpacePos(i+1)-SpacePos(i)-1)
> endfor
> return, SubString
> end

This is all great, but why stop here and return a vector of strings
when you can use READS to turn the string into array of numbers or a
structure. Actually, you can do this directly without doing any of
the searching for commas, tabs, or other delimiter and replacing them
with space characters.

Just do this:

READS,input_string,numbers

Where numbers is an array (intarr(10), or fltarr(12), or whatever)
or a structure a={f1: 0, f2: 0.0, f3: bytarr(100), ... }

This seems to me to be much easier to do.

BTW, this has zero loops as well.

Just my $0.02.


--
Joseph M. Zawodny (KO4LW) NASA Langley Research Center
Internet: j.m.zawodny@larc.nasa.gov MS-475, Hampton VA, 23681-0001
TCP/IP: ko4lw@ko4lw.ampr.org Packet: ko4lw@n4hog.va.usa.na
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Re: [Q}:Rubberbanding in IDL
Next Topic: Default Color for IDL Widgets.

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

Current Time: Fri Oct 10 09:33:37 PDT 2025

Total time taken to generate the page: 0.08262 seconds