DuanJinHui 发表于 2022-7-5 18:53:29

绳子被割断了???


;;---------------------=={ 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”)

DuanJinHui 发表于 2022-7-5 19:12:57

尊敬的各位
能理解吗?

rlx 发表于 2022-7-5 19:24:30

借用了李的一艘潜艇(thanx Lee)
 
 
(定义LM:sublst(lst idx len)
(条件
((null lst)nil)
(   (
((null len)lst)
(   (
)
)
(defun rlx:sublst(str nop/count l2 lst)
(if(and(>=(setq len(length(setq strlst(vl string->list str)))nop)
(setq l2(fix(/len nop))计数(fix(/len l2)))
(重复计数
(如果(>=(长度strlst)(*2 l2))
(setq lst(append lst(list(vl list->string(LM:sublst strlst 0 l2)))strlst(LM:sublst strlst l2 nil))
(setq lst(append lst(list(vl list->string(LM:sublst strlst 0 nil 1097;щщ)щ)'))
lst)
(定义c:tst()(rlx:sublst“abcdefghijklmnop”3))
 
 
我几乎可以肯定,李可以用一个更大胆的解决方案让我大吃一惊,但嘿,它确实起到了作用
 
 
gr.Rlx

DuanJinHui 发表于 2022-7-5 19:41:51

 
 
非常感谢。Rlx公司
好的它起作用了。
 
你为什么不喜欢这个格式代码?

rlx 发表于 2022-7-5 20:01:17

我在visual lisp编辑器中有这样的代码,但当我将其粘贴到这里并尝试使用编辑器中的#时,它不起作用。也许这是我工作时浏览器中的安全设置,我不知道。。。
 
 
 
 
你是welkom:-)
 
 
gr.Rlx
页: [1]
查看完整版本: 绳子被割断了???