TheSwamp
Code Red => AutoLISP (Vanilla / Visual) => Topic started by: andrew_nao on June 11, 2009, 11:35:35 AM
-
i have the following code to search a text file for a keyword
and makes a list of those keywords, it works but im looking to modify it to search a list for keywords and then make a new list of the keywords
can anyone help?
i appreciate any help and guidance
(setq TextFile "test.txt"))
(setq SearchStr "revision")
(setq Opened (open Textfile "r"))
(while (setq tmpLine (read-line Opened))
(if (vl-string-search (strcase SearchStr) (strcase tmpLine))
(setq EndList (cons tmpLine EndList))
)
)
-
Not sure if maybe this would work:
(setq kLst (mapcar 'strcase '("revision" "key2" "key3"))
ofile (open "test.txt" "r"))
(while (setq nl (read-line ofile))
(if (vl-some
(function
(lambda (x)
(vl-string-search x (strcase nl)))) kLst)
(setq EndList (cons nl EndList))))
(close ofile)
-
thanks for your reply
i guess i wasnt detailed enough
what im looking for is to search and existing list,
not open a text file and search it.
-
Use ' vl-remove-if-not ' and test each item for what you want. If it doesn't match, then it will be removed from the list.
Example
(vl-remove-if-not '(lambda ( x ) (equal x 1)) '(1 2 3 5 1 2 4 5 9 12))
return = (1 1)
-
Andrew, You're request is not clear to me.
Would you post a before list & an after list so we can see what you want?
-
<ding> <ding>
-
Andrew, You're request is not clear to me.
Would you post a before list & an after list so we can see what you want?
example would be
the text file would contain:
something something revision1
something something revision2
something something revision3
something something
something something
if the code i posted is loaded it would return
something something revision1
something something revision2
something something revision3
i would like to to do the same thing but search a list not a text file and make a new list with the keyword
-
Use ' vl-remove-if-not ' and test each item for what you want. If it doesn't match, then it will be removed from the list.
Example
(vl-remove-if-not '(lambda ( x ) (equal x 1)) '(1 2 3 5 1 2 4 5 9 12))
return = (1 1)
thanks Tim,
if my list is in a variable
how would i put my list in this formula?
-
As Tim said:
(setq lst '("something something revision1"
"something something revision2"
"something something revision3"
"something something "
"something something "
)
)
(vl-remove-if-not '(lambda (x) (wcmatch (strcase x) "*REVISION*")) lst)
Returns this
("something something revision1"
"something something revision2"
"something something revision3"
)
-
never mind, i see what i did wrong
thanks for everyones help
1 more small questioncan someone explain what lambda means?
-
Lambda is just an anonymous function defined to perform an operation.
-
Lambda is just an anonymous function defined to perform an operation.
hehe .. easy to say :)
.. but like juggling with knives in the dark, sometimes not so easy .. without lots of practice .. :|
-
Its explained very well here:
http://www.theswamp.org/index.php?topic=2953.msg37000#msg37000