本帖最后由 13816600495 于 2024-5-25 10:11 编辑
- (defun cl-string-split (str string / m n f n1 n2 list1 list2 list3 list4 lst)
- (setq list1 (vl-string->list str) n1 (length list1) list2 (vl-string->list string) n2 (length list2) n 0 tt t)
- (while (nth n list2)
- (setq lst nil m (1- n))
- (repeat n1
- (setq lst (cons (nth (setq m (1+ m)) list2) lst))
- )
- (if (not (equal list1 (reverse lst)))
- (progn
- (setq list3 (cons (nth n list2) list3))
- (setq n (1+ n))
- )
- (progn
- (if (= n 0) (setq list4 (cons "" list4)))
- (if (and f (= (- n f) n1)) (setq list4 (cons "" list4)))
- (setq f n n (+ n n1))
- (if list3 (setq list4 (cons (vl-list->string (reverse list3)) list4) list3 nil))
- (if (not (nth n list2)) (setq list4 (cons "" list4)))
- )
- )
- )
- (if list3 (setq list4 (cons (vl-list->string (reverse list3)) list4)))
- (reverse list4)
- )
->用法:
输入:str--指定的字符串
输入:string--要分割的字符串
->用法举例:
(defun c:pp ()
(cl-string-split "--" "日期--2023--05--24")
)
->返回: ("日期" "2023" "05" "24")
|