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 #3906 is a reply to message #3843] Wed, 29 March 1995 00:00 Go to previous message
cox is currently offline  cox
Messages: 1
Registered: March 1995
Junior Member
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.
;
; CATEGORY:
;
; CALLING SEQUENCE:
; substrings = parse_string(strng)
;
; POSITIONAL PARAMETERS:
; <INPUT>
; strng STRING A string containing multiple sub-
; strings separated by commas or by
; spaces.
; <INPUT/OUTPUT>
; None.
;
; <OUTPUT>
; None.
;
; KEYWORD PARAMETERS:
; None.
;
; MODIFICATION HISTORY:
; Written by: R.J. Cox, CPI, 1993
; Modified by: R.J. Cox, CPI, 2 Feb 1995
; Extensively recoded to make more use of
; built in IDL commands and to remove loops.
;-
;*********************************************************** **********
;
function parse_string, strng
;
;*********************************************************** **********
Separators = BYTE(', ')
ByteStrng = BYTE(strng)
;------------------------------------------
; replace commas by single spaces
;------------------------------------------
CommaPos = where(ByteStrng eq Separators(0), count)
if (count gt 0) then ByteStrng(CommaPos) = Separators(1)

;------------------------------------------
; Replace all whitespace by a single space
;------------------------------------------
strng_ = STRCOMPRESS(STRING(ByteStrng))
ByteStrng = BYTE(Strng_)
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


-------------------------
Robin Cox,
Computational Physics, Inc.
[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 07:37:56 PDT 2025

Total time taken to generate the page: 0.64028 seconds