AutoLISP文字大小写转换
2011-03-28 23:42 精诚所至 金石为开 阅读(785) 评论(0) 编辑 收藏 举报AutoLISP文字大小写转换,将首个字母转换成大写其余转换成小写,代码如下。
(defun c:test()
(prompt "\n选取文字:")
(setq ss (ssget))
(setq i 0)
(repeat (sslength ss)
(setq ssn (ssname ss i))
(setq ssdata (entget ssn))
(setq sstyp (cdr (assoc 0 ssdata)))
(if (= sstyp "TEXT")
(progn
(setq old_txt (assoc 1 ssdata))
(setq txt (cdr old_txt))
(chktxt)
(setq new_txt (cons 1 pp))
(setq ssdata (subst new_txt old_txt ssdata))
(entmod ssdata)
)
)
(setq i (1+ i))
)
)
(defun chktxt()
(setq p "" pp "" n 1 key nil)
(repeat (strlen txt)
(setq p (substr txt n 1))
(if (= n 1)
(setq key t)
(if (= pk " ") (setq key t) (setq key nil))
)
(if (= key nil)
(setq pp (strcat pp (strcase p t)))
(setq pp (strcat pp (strcase p)))
)
(setq n (1+ n))
)
)
(princ "\n------>>TEST<<------")
(prin1)
代码完。
只能对单行文字进行转换。
![](https://img2024.cnblogs.com/blog/35695/202408/35695-20240826070647288-243310440.jpg)