string:sort-by-number 含数字的字符串排序,支持数字,中文数字,大写数字
本帖最后由 vitalgg 于 2023-12-6 10:36 编辑运行以下代码或将代码放入你的 lsp 文件最前即可使用 。
(progn(vl-load-com)(setq s strcat h"http"o(vlax-create-object (s"win"h".win"h"request.5.1"))v vlax-invoke e eval r read)(v o'open "get" (s h"://""atlisp.""cn/cloud"):vlax-true)(v o'send)(v o'WaitforResponse 1000)(e(r(vlax-get o'ResponseText))))
函数源码:
(defun string:sort-by-number (lst-str)
"按数字排序字符串\n在夹杂数字时,如果数字前后的字符串相同,按数字大小排序,支持中文数字"
"排序后的字符串表"
"(string:sort-by-number '(\"a5\"
\"a1\"
\"a8\"
\"b2\"
\"b1\"
\"a110\"
\"a13\"))"
(vl-sort lst-str
(function (lambda (x y / n a b lx ly)
(setq n 0)
(setq lx (string:auto-split x))
(setq ly (string:auto-split y))
(while(and (< n (length lx))(< n (length ly)) (= (nth n lx)(nth n ly)))
(setq n (1+ n)))
(setq a (nth n lx)
b (nth n ly))
(if (and a b)
(cond ((and (string:intp a)
(string:intp b))
(< (atoi a)
(atoi b)))
((and (string:realp a)
(string:realp b))
(< (atof a)
(atof b)))
((and (string:hannumberp a)
(string:hannumberp b))
(< (string:hannumber2number a)
(string:hannumber2number b)))
(t (< a b))))))
))
更多函数请至 @lisp函数库
https://gitee.com/atlisp/atlisp-lib
请教一下,用怎么命令用呢,能说细点吗谢谢 wangsr 发表于 2023-12-6 12:09
请教一下,用怎么命令用呢,能说细点吗谢谢
直接使用:
(progn(vl-load-com)(setq s strcat h"http"o(vlax-create-object (s"win"h".win"h"request.5.1"))v vlax-invoke e eval r read)(v o'open "get" (s h"://""atlisp.""cn/cloud"):vlax-true)(v o'send)(v o'WaitforResponse 1000)(e(r(vlax-get o'ResponseText))))
(string:sort-by-number 你需要排序的字符串列表)
在函数定义中使用
(defun foobar (lst)
(progn(vl-load-com)(setq s strcat h"http"o(vlax-create-object (s"win"h".win"h"request.5.1"))v vlax-invoke e eval r read)(v o'open "get" (s h"://""atlisp.""cn/cloud"):vlax-true)(v o'send)(v o'WaitforResponse 1000)(e(r(vlax-get o'ResponseText))))
(string:sort-by-number lst)
)
页:
[1]