明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 1887|回复: 5

[提问] 抓取mtext文字 遇到新的问题

[复制链接]
发表于 2017-8-25 12:35:38 | 显示全部楼层 |阅读模式
本站高手写的抓取mtext文字
(defun c:tyu ()
  (setq ent (car (entsel "\n选择MTEXT文字:")))
  (setq dxf (entget ent))
  (setq str0 "")
  (setq txt (cdr (assoc 1 dxf)))
  (setq txt (vl-string-subst "" "{" txt))
  (setq txt (vl-string-subst "" "}" txt))
  (while (setq n (vl-string-search ";" txt))
    (if (= (setq str (substr txt 1 1)) "\\")
      (setq txt (substr txt (+ n 2)))
      (progn
(setq str0 (strcat str0 (substr txt 1 1)))
(setq txt (substr txt 2))
      )
    )
  )
  (setq str0 (strcat str0 txt))
  (princ (strcat "当前MTEXT中的文本为: " str0))
  (princ)
)

可是有个小问题
例如:  mtext里有
A:1111111
B:2222222
C:3333333
我想抓取C里面的文字
用(setq txt (substr txt (+ n 2))) 修改可以  
但是一旦 A跟B 的文字改变长短  
抓取C里面的文字 就会不正确
要如指定抓取?   请高手帮帮忙


发表于 2017-8-25 16:29:10 | 显示全部楼层
(setq txt (cdr (assoc 1 dxf)))
(setq Czfc (substr txt (+ (vl-string-search "C:" txt) 1))

评分

参与人数 1金钱 +6 收起 理由
倫到不行 + 6 赞一个!

查看全部评分

发表于 2017-8-26 09:26:40 | 显示全部楼层
获取“:”前面的所有字符怎么写。
发表于 2017-8-26 09:29:27 | 显示全部楼层
(setq txt (cdr (assoc 1 dxf)))
(setq Czfc (substr txt 1 (vl-string-search "C:" txt) ))
 楼主| 发表于 2017-8-28 08:54:14 | 显示全部楼层
yshf 发表于 2017-8-26 09:29
(setq txt (cdr (assoc 1 dxf)))
(setq Czfc (substr txt 1 (vl-string-search "C:" txt) ))

非常感谢你…再跟你请教  如果只要获取B:里面的内容 而其他内容不出现
要怎么修改  
发表于 2017-8-28 21:02:03 | 显示全部楼层
(setq n1 (vl-string-search "B:" txt))
(setq n2 (vl-string-search "C:" txt))          
(setq Bzfc (substr txt (1+ n1) (- n2 n1)))
(setq Bzfc (vl-string-subst "" "\\P" Bzfc))
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2025-5-20 02:40 , Processed in 0.181791 second(s), 27 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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