- ;;去除单行文字中的上下划线标志 ---多行文字中的上下标格式,与单行文字的格式不一样。炸开mt后dt会自动进行转换,导致字符串总长度有差异。
- (defun dtfix( str )
- (setq str (vl-string-subst "" "%%U" (vl-string-subst "" "%%O" str)))
- )
- ;;多行炸开变单行时,一些特殊的字符自动被转换,需要转换回去。
- (defun spdtfix( str )
- (setq str (vl-string-subst "%%p" "±" str)) ;\U+00B1
- (setq str (vl-string-subst "%%c" "\U+2205" str))
- (setq str (vl-string-subst "%%d" "°" str)) ;\U+00B0
- )
- ;;多行文字提取单行文字 --来自明经 --yuuboo改造,返回列表(list str str2biao) ::: str为脱格式后完整字符串,str2biao为考虑换行的字符串列表
- (defun mt2dt( MTextString / regex s s1 s2 )
- (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" "({|})")
- (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 "}"))
-
- ;;几个特殊符号更换大小写
- (setq s (vl-string-subst "%%p" "%%P" (vl-string-subst "%%d" "%%D" (vl-string-subst "%%c" "%%C" s))))
-
- ;;;换行处理1
- (setq s1 s)
- ;删除回车换行符格式
- (vlax-put-property regex "Pattern" "\\\\P")
- (setq s1 (vlax-invoke-method regex "Replace" s1 ""))
- ;删除换行符格式(针对Shift+Enter格式)
- (vlax-put-property regex "Pattern" "\n")
- (setq s1 (vlax-invoke-method regex "Replace" s1 ""))
-
- ;;;换行处理2
- (setq s2 s)
- ;回车换行符格式替换为 "\n"
- (vlax-put-property regex "Pattern" "\\\\P")
- (setq s2 (vlax-invoke-method regex "Replace" s2 "\\n"))
- ;回车换行符格式替换为 "\n"(针对Shift+Enter格式)
- (vlax-put-property regex "Pattern" "\n")
- (setq s2 (vlax-invoke-method regex "Replace" s2 "\\n"))
-
- (vlax-release-object regex)
- (list s1 (dos_strtokens s2 "\\n" T))
- )
|