How to parse a string in AutoLISP
Posted: Wed Aug 31, 2005 11:37 am
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
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