怎样去除多行文字里的控制符
提取出的多行文字里包含了“\p”、“\w”这些要怎么才能提取出纯的文本呢?
简单办法是炸开,上策是:正则表达式 自贡黄明儒 发表于 2018-6-7 16:45
简单办法是炸开,上策是:正则表达式
炸开不太合适
正则表达式怎么弄的?能说下吗 http://bbs.mjtd.com/thread-96376-1-1.html
;文字刷子程序
(defun wenzishua (entype entype_source ob source_text en1 ent)
; cad多行文字
(if (= entype "MTEXT")
(progn
(vla-put-TextString ob source_text)
(entupd en1)
(entupd ent)
)
)
;去掉多行文字无用格式符号
(if (= entype_source "MTEXT")
(setq source_text (mtext2text source_text))
)
; cad单行文字
(if (= entype "TEXT")
(progn
(vla-put-TextString ob source_text)
(entupd en1)
(entupd ent)
)
)
; 天正文字的内容格式刷
(if (or
(= entype "TCH_TEXT")
(= entype "TCH_ELEVATION")
)
(progn
(vlax-put-property ob 'Text source_text)
(entupd en1)
(entupd ent)
)
)
; 天正图名、标高的内容格式刷
(if (= entype "TCH_DRAWINGNAME")
(progn
(vlax-put-property ob 'NameText source_text)
(entupd en1)
(entupd ent)
)
)
; 属性文字 只改"标记"
(if (= entype "ATTDEF")
(progn
(vla-put-TagString ob source_text) ;改标记
(entupd en1)
(entupd ent)
)
)
; 块中属性文字 只改"默认"
(if (= entype "ATTRIB")
(progn
(vla-put-TextString ob source_text) ;改默认
(entupd en1)
(entupd ent)
)
)
)
;提取多行文字,去除无用格式符号--来自明经
(defun mtext2text (MTextString / regex s)
(setq regex (vlax-create-object "Vbscript.RegExp"))
;引用正则表达式控件
(vlax-put-property regex "IgnoreCase" 0) ;不忽略大小写
(vlax-put-property regex "Global" 1);匹配方式,全文字匹配
(setq s MTextString)
;替换\\字符
(vlax-put-property regex "Pattern" "\\\\\\\\")
(setq s (vlax-invoke-method regex "Replace" s (chr 1)))
;替换\{字符
(vlax-put-property regex "Pattern" "\\\\{")
(setq s (vlax-invoke-method regex "Replace" s (chr 2)))
;替换\}字符
(vlax-put-property regex "Pattern" "\\\\}")
(setq s (vlax-invoke-method regex "Replace" s (chr 3)))
;删除段落缩进格式
(vlax-put-property regex "Pattern" "\\\\pi(.[^;]*);")
(setq s (vlax-invoke-method regex "Replace" s ""))
;删除制表符格式
(vlax-put-property regex "Pattern" "\\\\pt(.[^;]*);")
(setq s (vlax-invoke-method regex "Replace" s ""))
;删除堆迭格式
(vlax-put-property
regex
"Pattern"
"\\\\S(.[^;]*)(\\^|#|\\\\)(.[^;]*);"
)
(setq s (vlax-invoke-method regex "Replace" s ""))
;删除字体、颜色、字高、字距、倾斜、字宽、对齐格式
(vlax-put-property
regex
"Pattern"
"(\\\\F|\\\\f|\\\\C|\\\\H|\\\\\T|\\\\Q|\\\\W|\\\\A)(.[^;]*);"
)
(setq s (vlax-invoke-method regex "Replace" s ""))
;删除下划线、删除线格式
(vlax-put-property
regex
"Pattern"
"(\\\\L|\\\\O|\\\\l|\\\\o)"
)
(setq s (vlax-invoke-method regex "Replace" s ""))
;删除不间断空格格式
(vlax-put-property regex "Pattern" "\\\\~")
(setq s (vlax-invoke-method regex "Replace" s ""))
;删除换行符格式
(vlax-put-property regex "Pattern" "\\\\P")
(setq s (vlax-invoke-method regex "Replace" s ""))
;删除换行符格式(针对Shift+Enter格式)
(vlax-put-property regex "Pattern" "\n")
(setq s (vlax-invoke-method regex "Replace" s ""))
;删除{}
(vlax-put-property regex "Pattern" "({|})")
(setq s (vlax-invoke-method regex "Replace" s ""))
;替换回\\,\{,\}字符
(vlax-put-property regex "Pattern" "\\x01")
(setq s (vlax-invoke-method regex "Replace" s "\\"))
(vlax-put-property regex "Pattern" "\\x02")
(setq s (vlax-invoke-method regex "Replace" s "{"))
(vlax-put-property regex "Pattern" "\\x03")
(setq s (vlax-invoke-method regex "Replace" s "}"))
(vlax-release-object regex)
s
) ㄘ丶转裑ㄧ灬 发表于 2018-6-8 08:47
http://bbs.mjtd.com/thread-96376-1-1.html
大佬怎么在这个基础上去除多行文字对齐样式如:\\pxql这类 蛋疼的东东 发表于 2023-6-27 19:39
大佬怎么在这个基础上去除多行文字对齐样式如:\\pxql这类
ㄘ丶转裑ㄧ灬 发表于 2023-6-28 17:03
太感谢啦
页:
[1]