CAD多行文本的读取
CAD中多行文本MTEXT读取如何实现,使用textstring获取的为一串字串,是否可以转换为文字,如何转换 用这个函数处理一下Public Function GetMTextUnformatString(MTextString As String) As String
Dim s As String
Dim RE As Object
' 获取Regular Expressions组件
Set RE = CreateObject("Vbscript.RegExp")
' 忽略大小写
RE.IgnoreCase = True
' 搜索整个字符串
RE.Global = True
s = MTextString
'替换\\字符
RE.Pattern = "\\\\"
s = RE.Replace(s, Chr(1))
'替换\{字符
RE.Pattern = "\\{"
s = RE.Replace(s, Chr(2))
'替换\}字符
RE.Pattern = "\\}"
s = RE.Replace(s, Chr(3))
'删除段落缩进格式
RE.Pattern = "\\pi(.[^;]*);"
s = RE.Replace(s, "")
'删除制表符格式
RE.Pattern = "\\pt(.[^;]*);"
s = RE.Replace(s, "")
RE.Pattern = "\\pxt(.[^;]*);" '删除制表符格式,新添加
s = RE.Replace(s, "")
'删除堆迭格式
RE.Pattern = "\\S(.[^;]*)(\^|#|\\)(.[^;]*);"
s = RE.Replace(s, "$1$3")
'删除字体、颜色、字高、字距、倾斜、字宽、对齐格式
RE.Pattern = "(\\F|\\C|\\H|\\T|\\Q|\\W|\\A)(.[^;]*);"
s = RE.Replace(s, "")
'删除下划线、删除线格式
RE.Pattern = "(\\L|\\O|\\l|\\o)"
s = RE.Replace(s, "")
'删除不间断空格格式
RE.Pattern = "\\~"
s = RE.Replace(s, " ")
'删除换行符格式
RE.Pattern = "\\P"
s = RE.Replace(s, "")
'删除换行符格式(针对Shift+Enter格式)
RE.Pattern = vbLf
s = RE.Replace(s, "")
'删除{}
RE.Pattern = "({|})"
s = RE.Replace(s, "")
'替换回\\,\{,\}字符
RE.Pattern = "\x01"
s = RE.Replace(s, "\")
RE.Pattern = "\x02"
s = RE.Replace(s, "{")
RE.Pattern = "\x03"
s = RE.Replace(s, "}")
Set RE = Nothing
GetMTextUnformatString = s
End Function
页:
[1]