« AutoCAD 2017 ObjectARX and Managed .NET Documentation | Main | Getting the Current Date/Time with AutoLISP - Part 1 »


José Luis García Galán

Only a small correction:
(Getenv "ACADPrefix") ";") is erroneous.

Use: (getvar "acadprefix") or (getenv "ACAD")


Lee Ambrosius

Thanks for catching the issue, the sample has been fixed. The original content I had wrote used an environment variable.


I think you'll find this old 'parser' routine offers a substantial boost in efficiency:


(defun _Parser (char string / i segments segment)
(while (setq i (vl-string-search char string))
(setq segments (cons (setq segment (substr string 1 i)) segments))
(setq string (substr string (+ 2 i)))
(reverse (cons string segments))

Here's a quick speed test:

(setq s (getvar "acadprefix"))
(setq d ";")
(bench '(split) (list s d) 10000)
(bench '(_Parser) '(d s) 10000)

... And the results from console:


Elapsed: 2922
Average: 0.2922

Elapsed: 32
Average: 0.0032

Now, how often will someone parse a string anywhere near this many times - admittedly seldom - just offering simplicity, and efficiency where I can, based on what I've learned.

Please do with this what you like.


Lee Ambrosius

Thanks for sharing! There is always different ways to approach the same solution and performance is key when working with large data sets.

The comments to this entry are closed.

My Photo

My Other Accounts

Twitter Updates

    follow me on Twitter