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

Home » Public Forums » archive » Re: 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 #3816] Fri, 17 March 1995 15:06 Go to previous message
metcalf is currently offline  metcalf
Messages: 3
Registered: May 1991
Junior Member
In article <3kb4ud$jv0@senator-bedfellow.MIT.EDU>, davis@space.mit.edu writes:
|> In article <3k89l3$2ap@news.csus.edu>, Chris McCarthy <chris@quark.sfsu.edu> writes:
|> : davis@space.mit.edu wrote:
|> : >
|> : > Hi,
|> : >
|> : > I was wondering if there is a routine that will read a string and convert
|> : > it to an array of floats. ...
|> :
|> : Have you tried reads?
|> :
|> : a = 0.d0 & b = 0.d0 & c = 0.d0
|> : reads,'9.32323 24323.233 22.124235555d-14',a,b,c
|> : print,c,b,a
|>


How about,

IDL> s = ' 9.32323 24323.233 22.124235555d-14 '
IDL> x = float(splitstr(strcompress(strtrim(s,2)),' '))


Where

;+
;NAME:
; SPLITSTR
;PURPOSE:
; Split a string into an array at specified character boundary
;CATEGORY:
;CALLING SEQUENCE:
; array = splitstr(string,character)
;INPUTS:
; string = string to be split
; character = character to split string on
;OPTIONAL INPUT PARAMETERS:
;KEYWORD PARAMETERS
;OUTPUTS:
; array = string array
;COMMON BLOCKS:
;SIDE EFFECTS:
;RESTRICTIONS:
; character must be a single character string, e.g. ' ' or 'a'
;PROCEDURE:
;EXAMPLES:
; array = splitstr('Hi There',' ')
; array(0) is 'Hi'
; array(1) is 'There'
;MODIFICATION HISTORY:
; T. Metcalf 1994-11-10
;-

function splitstr,line,char

cline = char+string(line(0))+char
place = where(byte(cline) eq (byte(char))(0))
nplace = n_elements(place)
strarray = strarr(nplace-1L)
strarray(0) = strmid(cline,place(0)+1L,place(1)-place(0)-1L)
for i = 1L,nplace-2L do begin
strarray(i) = strmid(cline,place(i)+1L,place(i+1L)-place(i)-1L)
endfor

return,strarray

end
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Previous Topic: Re: idl vs matlab question
Next Topic: 3d histograms

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

Current Time: Fri Oct 10 13:45:53 PDT 2025

Total time taken to generate the page: 0.15914 seconds