明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
12
返回列表 发新帖
楼主: xjf

数字后缀的字符串,按X排序

  [复制链接]
发表于 2012-12-25 14:49 | 显示全部楼层
本帖最后由 yuanziyou 于 2012-12-25 14:51 编辑
Andyhon 发表于 2012-12-23 18:43
另外一个处方:
下载 Lsort.Lsp By Tony Tanzillo
Ref: http://www.theswamp.org/index.php?topic=40302.0 ...

非常感谢!我已经把2个函数揉合了,一个就是g版的排序,另外一个论坛里搜索的正则表达式,完美解决
  1. (defun sort (l)
  2.   (vl-sort l
  3.            '(lambda (a b / a1 a2 b1 b2)
  4.               (setq a1 (zzth (car a) "[0-9]")
  5.                     a2 (zzth (car a) "[^0-9]")
  6.                     b1 (zzth (car b) "[0-9]")
  7.                     b2 (zzth (car b) "[^0-9]")
  8.               )
  9.               (if (= a1 b1)
  10.                 (< (atof a2) (atof b2))
  11.                 (< a1 b1)
  12.               )
  13.             )
  14.   )
  15. )
  16. (defun zzth (str gz / regex)
  17.   (vl-load-com)
  18.   (setq regex (vlax-create-object "Vbscript.RegExp"))
  19.   (vlax-put-property regex "IgnoreCase" 0)
  20.   (vlax-put-property regex "Global" 1)
  21.   (vlax-put-property regex "Pattern" gz)
  22.   (setq str (vlax-invoke-method  regex "Replace" str ""))
  23. )


点评

不错啊!  发表于 2015-7-22 13:50
回复

使用道具 举报

发表于 2014-4-13 18:42 | 显示全部楼层
yuanziyou 发表于 2012-12-25 14:49
非常感谢!我已经把2个函数揉合了,一个就是g版的排序,另外一个论坛里搜索的正则表达式,完美解决

正则表达式,不错的解决方式。赞一个。
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-4-19 03:30 , Processed in 0.181489 second(s), 16 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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