- ;;---------------------=={ String Wrap }==--------------------;;
- ;; ;;
- ;; Breaks a string at spaces (if possible) into a list of ;;
- ;; substrings of a specified length or less. ;;
- ;;------------------------------------------------------------;;
- ;; Author: Lee Mac, Copyright ? 2011 - www.lee-mac.com ;;
- ;;------------------------------------------------------------;;
- ;; Arguments: ;;
- ;; str - String to wrap to a specific length ;;
- ;; len - Maximum length of each substring ;;
- ;;------------------------------------------------------------;;
- ;; Returns: List of substrings of specified length or less ;;
- ;;------------------------------------------------------------;;
- (defun LM:StringWrap ( str len / pos )
- (if (< len (strlen str))
- (cons
- (substr str 1
- (cond
- ( (setq pos (vl-string-position 32 (substr str 1 len) nil t)))
- ( (setq pos (1- len)) len)
- )
- )
- (LM:StringWrap (substr str (+ 2 pos)) len)
- )
- (list str)
- )
- )
这是李的例行公事,按长度裁剪。
但我需要剪掉???
例如
str:“ABcdefGhij”
-$(StringWrap“ABcdefGhiJ”5)
_返回:(“AB”“cd”“ef”“Gh”“iJ”)
-$(StringWrap“ABcdefGhiJ”4)
_返回:(“AB”“cd”“ef”“GhiJ”)
-$(StringWrap“ABcdefGhiJ”3)
_返回:(“ABc”“def”“GhiJ”)
-$(StringWrap“ABcdefGhiJ”2)
_回报:(“ABcde”“fGhiJ”) |