+ Reply to Thread
Results 1 to 5 of 5
  1. #1
    Junior Member
    Using
    AutoCAD 2008
    Join Date
    Jun 2012
    Posts
    21

    Default string check - in a list

    Registered forum members do not see this ad.

    How can i check if one element in a list is a string?

  2. #2
    Forum Deity MSasu's Avatar
    Discipline
    Construction
    MSasu's Discipline Details
    Occupation
    engineer
    Discipline
    Construction
    Details
    AutoLISP programmer
    Using
    AutoCAD 2013
    Join Date
    Mar 2009
    Location
    Brasov, Romania
    Posts
    3,001

    Default

    The basic answer is to check the TYPE function:
    Code:
    (equal (type "abc") 'STR)
    But may be useful to give more details of your issue; you want to validate the element from a certain position, or if the list contains (at least) one string, or other scenario?
    Regards,
    Mircea

    AutoCAD's happy user equation: FILEDIA + PICKADD² + PICKFIRST = 3

  3. #3
    Quantum Mechanic Lee Mac's Avatar
    Computer Details
    Lee Mac's Computer Details
    Operating System:
    Windows 7 Ultimate (32-bit)
    Discipline
    Multi-disciplinary
    Lee Mac's Discipline Details
    Discipline
    Multi-disciplinary
    Details
    Custom Programming / Software Customisation
    Using
    AutoCAD 2013
    Join Date
    Aug 2008
    Location
    London, England
    Posts
    15,732

    Default

    Using vl-some:
    Code:
    (vl-some '(lambda ( x ) (= 'str (type x))) <your list>)
    Another, recursive:
    Code:
    (defun _stringinlist ( l )
        (and l (or (= 'str (type (car l))) (_stringinlist (cdr l))))
    )
    Lee Mac Programming

    With Mathematics there is the possibility of perfect rigour, so why settle for less?

    Just another Swamper

  4. #4
    Junior Member
    Using
    AutoCAD 2008
    Join Date
    Jun 2012
    Posts
    21

    Default

    I just wanted to eliminate strings from a list...thanks!

  5. #5
    Forum Deity MSasu's Avatar
    Discipline
    Construction
    MSasu's Discipline Details
    Occupation
    engineer
    Discipline
    Construction
    Details
    AutoLISP programmer
    Using
    AutoCAD 2013
    Join Date
    Mar 2009
    Location
    Brasov, Romania
    Posts
    3,001

    Default

    Registered forum members do not see this ad.

    Then:
    Code:
    (vl-remove-if '(lambda(x) (equal (type x) 'STR)) listToProcess)
    Regards,
    Mircea

    AutoCAD's happy user equation: FILEDIA + PICKADD² + PICKFIRST = 3

Similar Threads

  1. Converting a List into a String
    By Silvercloak in forum AutoLISP, Visual LISP & DCL
    Replies: 16
    Last Post: 23rd Mar 2012, 03:00 am
  2. How to check if a point is in a list ?
    By Michaels in forum AutoLISP, Visual LISP & DCL
    Replies: 8
    Last Post: 30th Oct 2011, 01:50 pm
  3. list convert to string - help
    By muthu123 in forum AutoLISP, Visual LISP & DCL
    Replies: 3
    Last Post: 10th Jun 2010, 11:17 am
  4. List to String
    By Lee Mac in forum AutoLISP, Visual LISP & DCL
    Replies: 3
    Last Post: 29th Dec 2008, 02:20 am
  5. vl-some to check if variable exists in list?
    By pracslipkerm in forum AutoLISP, Visual LISP & DCL
    Replies: 10
    Last Post: 1st Jun 2006, 09:37 am

Bookmarks

Posting Permissions

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