Sweety 发表于 2022-7-6 07:49:22

删除文本中的空格

你好
 
希望有人能告诉我如何删除选定文本或多行文字的空间。
 

(setq e (car (entsel "\n Select Text :")))
(setq ent (entget e))
(entmod (subst (cons 1 .......
 
具体内容不详。
 
谢谢大家。

BlackBox 发表于 2022-7-6 07:55:16

移除空间,还是用其他东西替换?
 
编辑:
我想删除和用空字符串替换是一样的,嗯。

Sweety 发表于 2022-7-6 07:56:45

不需要。只需从所选文本中删除所选单词的空格即可。
 
谢谢

BlackBox 发表于 2022-7-6 08:02:05


(defun c:FOO(/ ss)
(vl-load-com)
(vla-startundomark
   (cond (*activeDoc*)
         ((setq *activeDoc*
               (vla-get-activedocument (vlax-get-acad-object))))))
(if (setq ss (ssget '((0 . "TEXT,MTEXT"))))
   ((lambda (i / e v s)
      (while (setq e (ssname ss (setq i (1+ i))))
      (setq s (vla-get-textstring (setq v (vlax-ename->vla-object e))))
      (while (vl-string-search " " s)
          (setq s (vl-string-subst "" " " s)))
      (vla-put-textstring v s)))
   -1))
(vla-endundomark *activeDoc*)
(princ))

alanjt 发表于 2022-7-6 08:03:38

(defun noSpaces (str)
(if (eq (type str) 'STR)
   (vl-list->string (vl-remove 32 (vl-string->list str)))
)
)

alanjt 发表于 2022-7-6 08:07:00

仅供参考,如果要将实体编辑为vla对象,使用vla get-activeselectionset要比单步执行selectionset并转换为vla对象更快。

BlackBox 发表于 2022-7-6 08:09:00

 
双重注释。

Sweety 发表于 2022-7-6 08:13:35

非常感谢先生们。
 
Renderman你的日常工作做得很好。
 
Alanjt请看一看

(defun noSpaces (str)
(if (eq (type str) 'STR)
   (vl-list->string (vl-remove 32 (vl-string->list str)))
)
)

(setq e (car (entsel "\n Select Text :")))
(setq ent (entget e))
(setq tt (cdr (assoc 1 ent)))
(noSpaces tt)


 
在Visual Visp控制台中,我看到了更改,但这不会影响所选文本。
 
以前的代码有什么问题。
 
非常感谢

Lee Mac 发表于 2022-7-6 08:17:38

您需要使用Alan函数返回的textstring更新实体。
 
我想挑战自己,避免使用VL:
 

[ Scroll down after you have got something working on your own   ]








































(defun c:nospace ( / nospace ss )

(defun nospace ( s )
   (
   (lambda ( o )
       (repeat (strlen s)
         (if (/= 32 (ascii s))
         (setq o (strcat o (substr s 1 1)))
         )
         (setq s (substr s 2))
       )
       o
   )
   ""
   )
)

(if (setq ss (ssget "_:L" '((0 . "TEXT,MTEXT"))))
   (
   (lambda ( i / e )
       (while (setq e (ssname ss (setq i (1+ i))))
         (entupd
         (cdr
             (assoc -1
               (entmod
               (subst
                   (cons 1
                     (nospace
                     (cdr
                         (assoc 1 (entget e))
                     )
                     )
                   )
                   (assoc 1 (entget e))
                   (entget e)
               )
               )
             )
         )
         )
       )
   )
   -1
   )
)

(princ)
)

alanjt 发表于 2022-7-6 08:20:25

如果您没有意识到它只会编辑字符串,而不会编辑对象,那么您需要先学习编辑对象的基础知识,然后再继续。
页: [1] 2
查看完整版本: 删除文本中的空格