How to parse a string in AutoLISP

#1
Hi,

I want to parse a string with space delimiters into a list of strings. A search on Google threw up this code snippet:

; --- BEGIN AutoLISP code ---
(defun Str2List (str pat / i j n lst)
(cond
((/= (type str)(type pat) 'STR))
((= str pat)'(""))
(T
(setq i 0 n (strlen pat))
(while (setq j (vl-string-search pat str i))
(setq lst (cons (substr str (1+ i)(- j i)) lst)
i (+ j n)
)
)
(reverse (cons (substr str (1+ i)) lst))
)
)
)
; --- END AutoLISP code ---

But the Intellicad implementation of AutoLISP does not support the (vl-string-search) function - I think this is actually a VisualLISP fn ? I'm not sure...

So how would I modify this to work in Intellicad ? Is there an equivalent, or some other method ?

Thanks very much,
Raj

#3
One way to do this is to read each character of the string (read-char [file-descriptor]).
If the character is not a space then place it in a buffer (strcat string1 [string2] ...)
When you come to a space add the buffer to a list and start the buffer over.
Continue to parse the entire string.
cron