;把字符串转成表
;(STR->CHRS "比如把字符串反转遇到汉字lisp也无语")(vl-string->list "比如把字符串反转遇到汉字lisp也无语")
;返回:("比" "如" "把" ""符" "串" "反" "转" "遇" "到" "汉" "字" "l" "i" "s" "p" "也" "无" "语")
(defun str->chrs(str / a c)
(setq a(vl-string->list str))
(while a
(if(< (car a) 129)
(setq c (cons (chr (car a)) c) a (cdr a))
(setq c (cons (strcat (chr (car a)) (chr (cadr a))) c) a (cddr a))
)
)
(reverse c)
)
(apply 'strcat (reverse (STR->CHRS "比如把字符串反转遇到汉字lisp也无语")))
;反转字符串
;(revstr "比如把字符串反转遇到汉字lisp也无语")
;返回:"语无也psil字汉到遇转反串符字把如比"
(defun revstr(str / c)
(setq str (vl-string->list str))
(while str
(if(< (car str) 129)
(setq c (cons (chr (car str)) c) str (cdr str))
(setq c (cons (strcat (chr (car str)) (chr (cadr str))) c) str (cddr str))
)
)
(apply 'strcat c);(reverse c)
)
;字符串分割
;(STRCUT "比如把字符串反转遇到汉字lisp也无语" 2)
;返回:("比如" "把字" "符串" "反转" "遇到" "汉字" "li" "sp" "也无" "语")
(defun strcut(str leg / b c d n)
(setq str (vl-string->list str))
(while str
(if(< (car str) 129)
(setq c (cons (chr (car str)) c) str (cdr str))
(setq c (cons (strcat (chr (car str)) (chr (cadr str))) c) str (cddr str))
)
)
(setq n 1 b "")
(foreach x (reverse c) (if (= (rem n leg) 0) (progn (setq b (strcat b x) d (cons b d) b "")) (setq b (strcat b x))) (setq n (+ n 1)))
(if (/= b "") (setq d (cons b d)))
(reverse d)
)