去除含某个字符的元素列表
本帖最后由 duhan6401 于 2024-2-29 16:06 编辑我有这样的一个表,想去掉里面第四个元素不含进口也不含出口两个字的那个元素。这句是借鉴别人的,但是不对
[*](setq jzwsjnew(vl-remove-if-not '(lambda (x) (member ( wcmatch (cadddr x)"*进口/*出口")))jzwsj) )
[*](("False" "0" "343.02" "1#磨盘山隧洞进口" "333.3" "8" "False") ("1#磨盘山隧洞" "219.828"
[*]"342.5" "1#磨盘山隧洞出口" "333.186" "8" "False") ("1#埋管" "283.048" "341.6"
[*]"2#田龙湾隧洞进口" "332.81" "8" "False") ("2#田龙湾隧洞" "696.975" "342.5" "2#田龙湾隧洞出口"
[*]"332.67" "8" "False") ("2#埋管" "1640.668" "339.8" "3#猫湾隧洞进口" "329.22" "8"
[*]"False") ("3#猫湾隧洞" "1799.171" "337.5" "3#猫湾隧洞出口" "329.141" "8" "False") ("3#埋管"
[*]"1997.836" "339.7" "4#挖耳山隧洞进口" "328.15" "8" "False") ("4#挖耳山隧洞" "2089.393"
[*]"342" "4#挖耳山隧洞出口" "328.1" "8" "False") ("4#埋管" "5108.85" "318.4" "5#工业园隧洞进口"
[*]"329.22" "8" "False") ("5#工业园隧洞" "6697.795" "309" "5#工业园隧洞出口" "329.22" "8"
[*]"False") ("5#埋管" "7079.585" "307.6" "6#屋基嘴隧洞进口" "296.6" "8" "False") ("6#屋基嘴隧洞"
[*]"7209.585" "308" "6#屋基嘴隧洞出口" "296.535" "8" "False") ("6#埋管" "7251.585" "307.2"
[*]"7#毛狗山隧洞进口" "False" "8" "False") ("7#毛狗山隧洞" "7782.496" "308" "7#毛狗山隧洞出口"
[*]"False" "8" "False") ("7#埋管" "8165.7" "291.5" "2#大龙凼顶管进口" "False" "8" "False")
[*]("G348国道顶管" "8272.2" "293" "2#大龙凼顶管出口" "False" "8" "False") ("8#埋管" "9413.474"
[*]"279.9" "釜溪河管桥进口" "284.88" "8" "False"))
[*]最后我想只留下包含有隧洞进口或者隧洞出口字眼的那一个
本帖最后由 ssyfeng 于 2024-2-29 15:53 编辑
分开member,再用or函数就可以啦 本帖最后由 飞雪神光 于 2024-2-29 16:24 编辑
这是一种写法 去掉不包含关键字的第四个元素 保留该表
(defun del-lst-nth(num oldlist)
(setq num (1+ num))
(vl-remove-if'(lambda (x) (zerop (setq num (1- num))))oldlist)
)
(setq jzwsjnew
(mapcar
'(lambda (x)
(if
(and
(null (wcmatch (nth 3 x) "*隧洞进口"))
(null (wcmatch (nth 3 x) "*隧洞出口"))
)
(del-lst-nth 3 x)
x
)
)
jzwsj
)
)
这种写法是去掉不包含关键字的整个表
(setq jzwsjnew (vl-remove-if-not '(lambda (x) (or (wcmatch (nth 3 x) "*隧洞进口")(wcmatch (nth 3 x) "*隧洞出口"))) jzwsj)) 飞雪神光 发表于 2024-2-29 16:22
这种写法是去掉不包含关键字的整个表
这种是我想要的,谢谢大神啊。您是啥行业啊,这么溜 这个跟行业没关系 全靠写的多 写的越多就越溜 飞雪神光 发表于 2024-2-29 16:31
这个跟行业没关系 全靠写的多 写的越多就越溜
小白一个,后面还得多请教 (setq lst1 (vl-remove-if-not '(lambda (x)(or (vl-string-search "隧洞进口" (nth 3 x))(vl-string-search "隧洞进口" (nth 3 x))))lst))
页:
[1]