Jump to content

about Parse Numbers function...


ohhong2

Recommended Posts

hello.
I'm asking about the Parse Numbers function that I've seen in lee-mac.

This function does not seem to recognize the decimal point when a decimal point of 0 is added.

For example, 10.1 is recognized as 10.1, but 10.0 is recognized as 
10.0, but not 10.1.

How can I get it to literally recognize it as 10.0?

Thanks to lee-mac for letting me see the original function.

 

 

link: http://www.lee-mac.com/parsenumbers.html

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.

 

code

;; 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)

)

)

 

 

 


 

Link to comment
Share on other sites

8 hours ago, ohhong2 said:

For example, 10.1 is recognized as 10.1, but 10.0 is recognized as 
10.0, but not 10.1.

@ohhong2 Please clear out this sentence. 

And, please upload your sample.dwg

 

Edited by devitg
add comment
  • Like 1
Link to comment
Share on other sites

(defun Parse:Numbers+Decimals ( str )
  (vl-list->string
    (vl-remove-if-not
      (function
        (lambda ( u )
          (< 45 u 58)
          )
        )
      (vl-string->list str)
      )
    )
  ) (vl-load-com)

 

  • Like 1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...