srfi-152的库函数,之前断断续续写了好多篇,只是一直都不完整,这次争取把它弄完整喽。😂
autolisp、visual lisp内置了很多string函数,再加上这几回写的srfi152的实现,
绝大部分常见的string函数都全乎了,从srfi152往autolisp切换的话,基本上不会有明显障碍了。
string-count
string-count 用于统计符合条件的字符个数。
1
2
3
|
(defun string-count (a pred)
;; 作者:徐工, 微博:@徐工徐工2020,头条:@徐工徐工
(vl-list-length (vl-remove-if 'null (mapcar pred (string-explode a)))))
|
string-remove-if
string-remove-if 相当于字符串版的 vl-remove-if,在srfi152里边被称作string-remove。
1
2
3
4
5
6
7
|
(defun string-remove-if (a pred / o)
;; 作者:徐工, 微博:@徐工徐工2020,头条:@徐工徐工
(setq o "")
(foreach e (string-explode a)
(if (not (apply pred e))
(setq o (strcat o e))))
o)
|
string-remove-if-not
string-remove-if-not 相当于字符串版的 vl-remove-if-not,在srfi152里边被称作string-filter。
1
2
3
4
5
6
7
|
(defun string-remove-if-not (a pred / o)
;; 作者:徐工, 微博:@徐工徐工2020,头条:@徐工徐工
(setq o "")
(foreach e (string-explode a)
(if (apply pred e)
(setq o (strcat o e))))
o)
|
string-segment
string-segment 用于分割字符串,相当于字符串版的 group。
1
2
3
|
(defun string-segment (a k)
;; 作者:徐工, 微博:@徐工徐工2020,头条:@徐工徐工
(mapcar 'string-concatenate (group (string-explode a) k)))
|
文章作者
Jack Hsu
上次更新
2023-12-07
许可协议
Copyright © Jack Hsu. All Rights Reserved.