明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 855|回复: 1

[提问] 求助大神 请问如何实现数值+字母的排序

[复制链接]
发表于 2019-3-2 16:12:29 | 显示全部楼层 |阅读模式
我的list 的数据是这样的
!aa
(("a" "b" "L1-01")("a" "b" "L1-02")("a" "b" "B2-02")("a" "b" "B2-01") ("a" "b" "B2-03")("a" "b" "L2-01")("a" "b" "B1-01")("a" "b" "B1-02"))

需要排列顺序是:B→L、前序B时数值大→小、前序L时数值小→大、末尾数值小→大,同时需要小括号整体跟着排序,如下:
(("a" "b" "B3-01") ("a" "b" "B2-01")("a" "b" "B2-02")("a" "b" "B1-01")("a" "b" "B1-02")("a" "b" "L1-01")("a" "b" "L1-02")("a" "b" "L2-01"))

我研究vl-sort很久都没想出办法排序,求大神解决。。。
 楼主| 发表于 2019-3-3 23:09:39 | 显示全部楼层
本帖最后由 fs_lzh1988 于 2019-3-3 23:16 编辑

自己想办法解决了,但是感觉很啰嗦,想不到其他方法了
(setq l_nnt (vl-sort l_nnt (function (lambda (x y)

(cond ((< (substr (nth 2 x) 1 1) (substr (nth 2 y) 1 1)) t)       
                                                                                       
( (and (= (substr (nth 2 x) 1 1) (substr (nth 2 y) 1 1) "B")
(> (atof (substr (nth 2 x) 2 1)) (atof (substr (nth 2 y) 2 1)) )) t )

( (and (= (substr (nth 2 x) 1 1) (substr (nth 2 y) 1 1) "B")
(= (atof (substr (nth 2 x) 2 1)) (atof (substr (nth 2 y) 2 1)) )
(< (atof (substr (nth 2 x) 4 2)) (atof (substr (nth 2 y) 4 2)) )) t )   
                              
  ( (and (= (substr (nth 2 x) 1 1) (substr (nth 2 y) 1 1) "L")
(< (atof (substr (nth 2 x) 2 1)) (atof (substr (nth 2 y) 2 1)) )) t )
       
( (and (= (substr (nth 2 x) 1 1) (substr (nth 2 y) 1 1) "L")
(= (atof (substr (nth 2 x) 2 1)) (atof (substr (nth 2 y) 2 1)) )
(< (atof (substr (nth 2 x) 4 2)) (atof (substr (nth 2 y) 4 2)) )) t )         
                                                                                               
  (t NIL)
)                                                                                                                                                               
)
)
)
)


您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2025-5-19 01:22 , Processed in 0.189970 second(s), 26 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表