Jump to content

Recommended Posts

Posted

Hi all,

 

 

I want search a string in list using lisp can any body help me.

 

ex (setq a (list "1" "2" "3"))

now i want to search "2" in a list.

 

thank you

Posted

just pass the list and search string to function

 

ex:

 

(defun c:test(/ a yes)

(setq a (list "1" "2" "3"))

(setq yes (searchstring a "2"))

(if(= yes t)

(prompt "found")

(prompt "Not found")

)

)

 

 

 

(defun searchstring(searchlist search / sealen sea anwser str)

(setq sealen (length searchlist))

(setq sea 0)

(setq anwser nil)

(while(

(setq str (nth sea searchlist))

(if(= (strcase search)(strcase str))

(progn

(setq anwser t)

)

)

(if(= anwser t)

(setq sea sealen)

)

(setq sea (+ 1 sea))

)

anwser

)

Posted

You can check if a member if found in a list with member function .

 

e.g.

 

(setq a (list "1" "2" "3"))
(member "2" a)

  • Like 1
Posted

Thank you Tharwat for reply.

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...