本帖最后由 hubeiwdlue 于 2025-2-25 09:31 编辑
 - (defun wdl_str->lst (string strkey / po strlst xlen)
- (setq xlen (1+ (strlen strkey)))
- (while (setq po (vl-string-search strkey string))
- (setq strlst (cons (substr string 1 po) strlst))
- (setq string (substr string (+ po xlen)))
- )
- (vl-remove "" (reverse (cons string strlst)))
- )
- ;剪切字符串保留左侧部分字符串
- ;srting,被剪切字符串,dstr,剪切字符,flag控制参数,t返回值不删除dstr本身,nil返回值删除dstr本身
- (defun str-left-trim(string dstr flag / newstr1 newstr2 strlst strlst1)
- (setq strlst (wdl_str->lst string dstr))
- (setq strlst1 (reverse(cdr(reverse strlst))))
- (setq newstr1 (apply 'strcat (mapcar '(lambda (x) (strcat x dstr)) strlst1)))
- (setq newstr2 (substr newstr1 1 (- (strlen newstr1) (strlen dstr))))
- (if flag
- newstr1
- newstr2
- )
- )
- ;剪切字符串保留右侧部分字符串
- ;srting,被剪切字符串,dstr,剪切字符,flag控制参数,t返回值不删除dstr本身,nil返回值删除dstr本身
- (defun str-right-trim(string dstr flag / newstr1 newstr2 strlst strlst1)
- (setq strlst (wdl_str->lst string dstr))
- (setq strlst1 (cdr strlst))
- (setq newstr1 (apply 'strcat (mapcar '(lambda (x) (strcat dstr x)) strlst1)))
- (setq newstr2 (substr newstr1 (1+ (strlen dstr)) (strlen newstr1)))
- (if flag
- newstr1
- newstr2
- )
- )
- (str-left-trim "祖//国//万//岁" "//" t);"祖//国//万//"
- (str-left-trim "祖//国//万//岁" "//" nil);"祖//国//万"
|