Parse Numbers
Function Syntax | (LM:parsenumbers <str>) |
Current Version | 1.0 |
Donate |
Arguments | ||
---|---|---|
Symbol | Type | Description |
str | String | String from which to extract numerical values |
Returns | ||
Type | Description | |
List | List of numbers found in supplied string, else nil |
Function Description
This function will extract numbers from a supplied string, returning a list of all numerical values found in the string.
There is much ambiguity surrounding what constitutes a valid representation of number in a string. Some functions may permit fractional representations, whilst others include numerical quantities, such as measurements in feet & inches.
This function is engineered solely for extraction of numbers represented in decimal format and uses the same rules for validity as the AutoLISP interpreter.
Select all
;; Parse Numbers - Lee Mac ;; Parses a list of numerical values from a supplied string. (defun LM:parsenumbers ( str ) ( (lambda ( l ) (read (strcat "(" (vl-list->string (mapcar '(lambda ( a b c ) (if (or (< 47 b 58) (and (= 45 b) (< 47 c 58) (not (< 47 a 58))) (and (= 46 b) (< 47 a 58) (< 47 c 58)) ) b 32 ) ) (cons nil l) l (append (cdr l) '(())) ) ) ")" ) ) ) (vl-string->list str) ) )
Example Function Call
_$ (LM:parsenumbers "1a-2.3b4c56") (1 -2.3 4 56)