明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 2620|回复: 6

如何提取括号内的字符串

[复制链接]
发表于 2005-9-23 22:26:00 | 显示全部楼层 |阅读模式
如何提取括号内的字符串
发表于 2005-9-24 05:52:00 | 显示全部楼层

说具体些.

 楼主| 发表于 2005-9-24 10:34:00 | 显示全部楼层
思路:点取字符串:8989(3)提取字符中括号内的3,输入新值4,最后返回的字符串为:8989(4)
发表于 2005-9-24 18:40:00 | 显示全部楼层
  1. (load "xyp_lib")
  2. ;|加载通用函数(可在签名栏直接下载)
  3. 如果已经下载xyp_lib并放到搜索路径下可以不再下载!
  4. 利用以下任何一种方式即可加载和运行通用函数内的所有子程序:
  5. 1.在acad.lsp中增加(load"xyp_lib")
  6. 2.在每个程序内增加(load"xyp_lib")
  7. 3.在command下,输入(load"xyp_lib")
  8. 4.在菜单.mnl中增加(load"xyp_lib")
  9. 5.将xyp_lib.vlx文件直接拽到cad屏幕
  10. [COLOR=red] ★通用函数下载地址:[/COLOR]
  11. [url]http://www.xdcad.net/forum/attachment.php?s=&postid=1606661[/url]
  12. [url]http://bbs.mjtd.com/forum.php?mod=viewthread&tid=37554[/url]|;
  13. ;;;批量更换括号内的字符串:8989(3)→8989(新字符)
  14. (defun c:test ()
  15.   (setq txt1 (USTR 1 "\n输入括号内新字符" txt1 nil)
  16. ss   (ssget '((0 . "TEXT")))
  17. i    -1
  18.   )
  19.   (while (setq s1 (ssname ss (setq i (1+ i))))
  20.     (setq txt (DXF 1 (entget s1))
  21.    n1  (vl-string-search "(" txt)
  22.    n2  (vl-string-search ")" txt)
  23.     )
  24.     (if (and n1 n2 (> n2 n1))
  25.       (progn (setq txt (strcat (substr txt 1 (+ n1 2))
  26.           txt1
  27.           ")"
  28.          )
  29.       )
  30.       (SUB_UPD s1 1 txt)
  31.       )
  32.       (progn
  33. (setq n1 (vl-string-search "(" txt)
  34.        n2 (vl-string-search ")" txt)
  35. )
  36. (if (and n1 n2 (> n2 n1))
  37.    (progn (setq txt (strcat (substr txt 1 (+ n1 1))
  38.        txt1
  39.        ")"
  40.       )
  41.    )
  42.    (SUB_UPD s1 1 txt)
  43.    )
  44. )
  45.       )
  46.     )
  47.   )
  48.   (princ)
  49. )
 楼主| 发表于 2005-9-26 19:53:00 | 显示全部楼层
老大,试用过了,有点小问题!如果括号内文字多于两个,则只能改最后一个字,其它的不会变
发表于 2013-2-1 16:19:52 | 显示全部楼层
用app加载,不能用。。。提示的那几个方法不懂!!!
发表于 2013-2-1 19:13:08 | 显示全部楼层
举例,好对症下药
您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2025-6-1 06:41 , Processed in 0.170585 second(s), 25 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表