See the top rated post in this thread. Click here

Results 1 to 7 of 7

Thread: Need a lisp that can extract the numbers from selected Text

  1. #1
    Login to Give a bone
    0

    Default Need a lisp that can extract the numbers from selected Text

    Dear All,

    I need a lisp that extract numbers seperately from selected texts.

    CASE1 (Remove all Alphabets) : I need a lisp that can remove all the alphabets from selected texts For example the "Motor 125 kW" text is there in autocad. I need to get the return value "125" only, that should replace the original one.

    CASE2: (Remove Prefix Alphabets) : I need a lisp that can remove all the prefix alphabets from selected texts. For example the "Motor 125 kW" text is there in autocad. I need to get the return value "125 kW" only, that should replace the original one.

    CASE3: (Remove suffix Alphabets) : I need a lisp that can remove all the suffix alphabets from selected texts. For example the "Motor 125 kW" text is there in autocad. I need to get the return value "Motor 125" only, that should replace the original one.

    Thanks in advance,
    T.Brahmanandam.

  2. #2
    Member
    Join Date
    2016-02
    Location
    Italy - Benevento
    Posts
    2
    Login to Give a bone
    0

    Default Re: Need a lisp that can extract the numbers from selected Text

    Try that subfunctions; I have prepared them quickly and don't guarantee correct results in every case.


    (defun CHR2LST (str$ / chr@)
    (while (/= str$ "") (setq chr@ (append chr@ (list (substr str$ 1 1)))) (setq str$ (substr str$ 2)))
    chr@)

    (defun TRIM_ALL_ALPHCHR (chr@ / str$)
    (setq str$ "")
    (mapcar '(lambda (x$)
    (if (< 47 (ascii x$) 58)
    (setq str$ (strcat str$ x$))))
    chr@)
    str$)

    (defun TRIM_LEFT_ALPHCHR (chr@ / cont str$ rst@)
    (setq cont 0)
    (while (and (not (< 47 (ascii (setq str$ (nth cont chr@))) 58)) (< cont (length chr@)))
    (setq rst@ (cdr (member str$ chr@)))
    (setq cont (1+ cont)))
    rst@)

    ; Test
    (setq numstr$ (TRIM_ALL_ALPHCHR (CHR2LST "motore 125 kW")))
    (setq rightstr$ (apply 'strcat (TRIM_LEFT_ALPHCHR (CHR2LST "motore 125 kW"))))
    (setq leftstr$ (apply 'strcat (reverse(TRIM_LEFT_ALPHCHR (reverse(CHR2LST "motore 125 kW"))))))

  3. #3
    Login to Give a bone
    0

    Default Re: Need a lisp that can extract the numbers from selected Text

    Dear Sir,

    First of all, Thanks for efforts, those you put on my querry.

    I am not getting the outputs when I am using this program.

    Thanks & Regards,
    T.Brahmanandam.

  4. #4
    Member
    Join Date
    2016-02
    Location
    Italy - Benevento
    Posts
    2
    Login to Give a bone
    0

    Default Re: Need a lisp that can extract the numbers from selected Text

    You must first open Visual Lisp editor and open a "new file", that will automatically name "Anonimous-0".
    Copy the code I have alleged in my post (all the subfunctions and the final commands of test), and paste in the file.
    Finally launch them with the icon "Load in active editor window" (I have the italian editor and maybe this is not the exact text of the icon if you have an other language's editor. By the way, the command is also in the "tools" menu).
    In this way you can read the results of each command in variables numstr$ rightstr$ leftstr$.
    This is the most rapid way to prove the running of subfunctions, and them all were perfectly working.

  5. #5
    Login to Give a bone
    1

    Default Re: Need a lisp that can extract the numbers from selected Text

    Quote Originally Posted by brahmanandam.thadikonda762224 View Post
    Dear All,

    I need a lisp that extract numbers seperately from selected texts.

    CASE1 (Remove all Alphabets) : I need a lisp that can remove all the alphabets from selected texts For example the "Motor 125 kW" text is there in autocad. I need to get the return value "125" only, that should replace the original one.

    CASE2: (Remove Prefix Alphabets) : I need a lisp that can remove all the prefix alphabets from selected texts. For example the "Motor 125 kW" text is there in autocad. I need to get the return value "125 kW" only, that should replace the original one.

    CASE3: (Remove suffix Alphabets) : I need a lisp that can remove all the suffix alphabets from selected texts. For example the "Motor 125 kW" text is there in autocad. I need to get the return value "Motor 125" only, that should replace the original one.

    Thanks in advance,
    T.Brahmanandam.

    I use :

    Code:
    (defun ripcar (s)
      (vl-list->string (vl-remove-if '(lambda(x)(or (< x 48)(> x 57)))(vl-string->list s))))
    (defun ripnum (s)
      (vl-list->string (vl-remove-if '(lambda(x)(and (< x 58)(> x 47)))(vl-string->list s))))
    gr. Fikkie

  6. #6
    Woo! Hoo! my 1st post
    Join Date
    2016-12
    Posts
    1
    Login to Give a bone
    0

    Default Re: Need a lisp that can extract the numbers from selected Text

    I can help u



    Hello
    if u r still needing that program i can help u.
    Tell me to guide u
    Amir

  7. #7
    All AUGI, all the time
    Join Date
    2003-07
    Posts
    561
    Login to Give a bone
    0

    Default Re: Need a lisp that can extract the numbers from selected Text

    Case 1 use www.Lee-mac.com parse.lsp
    Case 2 use substr and check each character remove if a-z A-Z
    Case 3 similar parse the string 1st and can find the ending character 125 then remove anything past.
    Case3 or look at last Charactersubstr if a-z A-Z remove keep going till hit a number.

    Look at Parse.lsp it will give all the clues how to compare a character it uses the ascii code numbers for characters.

    (ascii "A") 65
    Z 90
    a 97
    z 122
    0 48
    9 57

Similar Threads

  1. Replies: 2
    Last Post: 2016-01-11, 03:00 PM
  2. Switch places on numbers in a text with a LISP routine?
    By kristian380590 in forum AutoLISP
    Replies: 12
    Last Post: 2013-05-27, 12:24 PM
  3. Change all selected numbers to be in sequence
    By Cadtharsis in forum AutoCAD General
    Replies: 3
    Last Post: 2007-03-29, 08:34 PM
  4. Extract nested attributes by selected blocks
    By charlie.bauer341340 in forum AutoLISP
    Replies: 4
    Last Post: 2006-12-19, 04:31 PM
  5. Lisp to extract and add numbers from text/mtext string
    By cblendermann.91943 in forum AutoLISP
    Replies: 26
    Last Post: 2005-08-18, 03:25 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •